diff --git a/src/utils/time.ts b/src/utils/time.ts index 698b05a..7c9180d 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -9,10 +9,10 @@ */ import { getStoredLanguage } from "../utils/languageStorage"; -export function gettime(data = null,type = 1) { +export function gettime(data = null, type = 1) { var time if (data) { - data instanceof Date? time=data : time = new Date(data); + data instanceof Date ? time = data : time = new Date(data); } else { time = new Date(); } @@ -38,14 +38,14 @@ export function gettime(data = null,type = 1) { if (minutes < 10) minutes = "0" + minutes; if (seconds < 10) seconds = "0" + seconds; - if(type==1){ + if (type == 1) { return year + "-" + month + "-" + dates + " " + hours + ':' + minutes + ':' + seconds + ' ' + arr[day]; - }else if (type == 2){ + } else if (type == 2) { return year + "-" + month + "-" + dates + " " + hours + ':' + minutes + ':' + seconds; - }else{ + } else { return year + "-" + month + "-" + dates + " " + hours + ':' + minutes + ':' + seconds + ' ' + arr[day]; } - + } export function clacendTime(endtime, nowtime) { let newDate = Math.abs(endtime - nowtime) @@ -55,3 +55,17 @@ export function clacendTime(endtime, nowtime) { var s = Math.floor(newDate / 1000 % 60) return day + '天' + h + '时' + m + '分' + s + '秒' } + +//时间戳转换 +export function timestampToTime(timestamp) { + const startDate = new Date(0); // 0 就是 1970年1月1日 + const targetDate = new Date(timestamp); + const diff = targetDate.getTime() - startDate.getTime(); // 计算时间差(毫秒) + // let day = Math.floor(diff / (1000 * 60 * 60 * 24)); // 转换为天数 + let hour = (Math.floor(diff / (1000 * 60 * 60) % 24)) < 10 ? '0'+(Math.floor(diff / (1000 * 60 * 60) % 24)) :(Math.floor(diff / (1000 * 60 * 60) % 24)); // 转换为小时 + let minute = Math.floor(diff / (1000 * 60) % 60) < 10 ? '0'+Math.floor(diff / (1000 * 60) % 60) :Math.floor(diff / (1000 * 60) % 60); // 转换为分钟 + let second = Math.floor(diff / 1000 % 60) < 10 ? '0'+Math.floor(diff / 1000 % 60):Math.floor(diff / 1000 % 60); // 转换为秒 + + return `${hour}:${minute}:${second}`; +} + diff --git a/src/views/MicrofactoryDevOnline/components/RingChart.vue b/src/views/MicrofactoryDevOnline/components/RingChart.vue index 7bb293a..059a69d 100644 --- a/src/views/MicrofactoryDevOnline/components/RingChart.vue +++ b/src/views/MicrofactoryDevOnline/components/RingChart.vue @@ -7,7 +7,11 @@