|
@@ -210,7 +210,39 @@ const format = (obj) => {
|
|
|
Minutes = Minutes > 9 ? Minutes : '0' + Minutes;
|
|
|
return `${year}-${month}-${day}` + ' ' + Hours + ':' + Minutes;
|
|
|
}
|
|
|
+// 将时间戳转化为指定时间
|
|
|
+// way:方式(1=年月日,2=年月日时分秒)默认1, 也可以指定格式:yyyy-MM-dd HH:mm:ss
|
|
|
+const forDate = (inputTime, way) => {
|
|
|
+ var date = new Date(inputTime);
|
|
|
+ var y = date.getFullYear();
|
|
|
+ var m = date.getMonth() + 1;
|
|
|
+ m = m < 10 ? ('0' + m) : m;
|
|
|
+ var d = date.getDate();
|
|
|
+ d = d < 10 ? ('0' + d) : d;
|
|
|
+ var h = date.getHours();
|
|
|
+ h = h < 10 ? ('0' + h) : h;
|
|
|
+ var minute = date.getMinutes();
|
|
|
+ var second = date.getSeconds();
|
|
|
+ minute = minute < 10 ? ('0' + minute) : minute;
|
|
|
+ second = second < 10 ? ('0' + second) : second;
|
|
|
+ var ms = date.getMilliseconds();
|
|
|
|
|
|
+ way = way || 1;
|
|
|
+ // way == 1 年月日
|
|
|
+ if (way === 1) {
|
|
|
+ return y + '-' + m + '-' + d;
|
|
|
+ }
|
|
|
+ // way == 1 年月日时分秒
|
|
|
+ if (way === 2) {
|
|
|
+ return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
|
|
|
+ }
|
|
|
+ // way == 具体格式 标准格式: yyyy-MM-dd HH:mm:ss
|
|
|
+ if (typeof way == 'string') {
|
|
|
+ return way.replace("yyyy", y).replace("MM", m).replace("dd", d).replace("HH", h).replace("mm", minute)
|
|
|
+ .replace("ss", second).replace("ms", ms);
|
|
|
+ }
|
|
|
+ return y + '-' + m + '-' + d;
|
|
|
+}
|
|
|
module.exports = {
|
|
|
formatTime: formatTime,
|
|
|
formatLocation: formatLocation,
|
|
@@ -222,5 +254,6 @@ module.exports = {
|
|
|
getDaysBetween: getDaysBetween,
|
|
|
getdiffdate: getdiffdate,
|
|
|
selectDictLabel: selectDictLabel,
|
|
|
- hasPermi:hasPermi
|
|
|
+ hasPermi: hasPermi,
|
|
|
+ forDate:forDate
|
|
|
}
|