Przeglądaj źródła

导出加日期

chris 3 lat temu
rodzic
commit
689278af9e
1 zmienionych plików z 21 dodań i 0 usunięć
  1. 21 0
      src/api/util.js

+ 21 - 0
src/api/util.js

@@ -58,3 +58,24 @@ export function checkStr (currentStr, strList) {
   let index = list.findIndex(item => item === currentStr)
   return index > -1
 }
+
+/**
+ * 日期处理:字符串转日期
+ */
+export function strToDate (str) {
+  if (!str) return null
+  return dateToString(Date.parse(str))
+}
+export function dateToString (date) {
+  let date1 = new Date(date)
+  const year = date1.getFullYear() + ''
+  let month = (date1.getMonth() + 1) + ''
+  let day = (date1.getDate()) + ''
+  if (month.length === 1) {
+    month = '0' + month
+  }
+  if (day.length === 1) {
+    day = '0' + day
+  }
+  return year + '-' + month + '-' + day
+}