From be51bb0a4f9543c56a7792f6e9696847e048ce88 Mon Sep 17 00:00:00 2001 From: YunLei Date: Wed, 9 Nov 2022 09:55:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BD=AC=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Timestamp.vue | 89 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/src/views/Timestamp.vue b/src/views/Timestamp.vue index 09f83f2..82ad7bf 100644 --- a/src/views/Timestamp.vue +++ b/src/views/Timestamp.vue @@ -80,6 +80,41 @@ @click="copyText('copy-timestamp2')">复制时间戳 + +
+ 时间转化: + + + + + + + + + 转化 +
+
+
毫秒:{{timeObj.ms}}
+
秒:{{timeObj.s}}
+
分:{{timeObj.min}}
+
时:{{timeObj.hour}}
+
天:{{timeObj.day}}
+
@@ -104,6 +139,9 @@ export default { timestamp2: 0, dateStr1: "", dateStr2: "", + time: 86400, + timeType: "2", + timeObj:{}, } }, //监听属性 类似于data概念 @@ -121,7 +159,7 @@ export default { //生命周期 - 挂载完成(可以访问DOM元素) async mounted () { this.nowTime(); - + this.transformClick (); let curr = dayjs(); this.timestamp1 = curr.unix(); this.timestamp2 = curr.unix(); @@ -179,6 +217,52 @@ export default { return false; } this.timestamp2 = dayjs(this.dateStr2).unix(); + }, + ms2Time (ms) { + let s = ms / 1000; + let min = s / 60; + let hour = min / 60; + let day = hour / 24; + + return { + ms, + s, + min, + hour, + day + } + }, + transformClick () { + let time = Number(this.time); + if (!time) { + this.$message.error("格式不正确!"); + return false; + } + let ms = 0; + let timeObj = {}; + switch (Number(this.timeType)) { + case 1: + ms = time; + timeObj = this.ms2Time(ms); + break; + case 2: + ms = time * 1000; + timeObj = this.ms2Time(ms); + break; + case 3: + ms = time * 1000 * 60; + timeObj = this.ms2Time(ms); + break; + case 4: + ms = time * 1000 * 60 * 60; + timeObj = this.ms2Time(ms); + break; + case 5: + ms = time * 1000 * 60 * 60 * 24; + timeObj = this.ms2Time(ms); + break; + } + this.timeObj = timeObj; } }, //当前页面的filter @@ -202,6 +286,9 @@ export default { margin-left: 20px; margin-right: 20px; } +.ml20 { + margin-left: 20px; +} \ No newline at end of file