瀏覽代碼

兼容:参数不对返回空

lifanagju_citu 10 月之前
父節點
當前提交
52ffc9c181
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      src/utils/date.js

+ 2 - 0
src/utils/date.js

@@ -1,5 +1,6 @@
 // 时间戳转换为年月日时分秒
 export const timesTampChange = (timestamp) => {
+  if (!timestamp) return ''
   const date = new Date(timestamp)
   const Y = date.getFullYear() + '-'
   const M = (date.getMonth() + 1).toString().padStart(2, '0') + '-'
@@ -14,6 +15,7 @@ export const timesTampChange = (timestamp) => {
 
 // 将 Wed May 01 2024 00:00:00 GMT+0800 (中国标准时间) 转换为时间戳
 export const getTimeStamp = (str) => {
+  if (!str) return ''
   const date = new Date(str)
   return date.getTime()
 }