From daf3696fbaac76766cfc12fa7279aa941c79bb3f Mon Sep 17 00:00:00 2001 From: liaoxinyu Date: Tue, 11 Mar 2025 19:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=98=AF=E7=BE=8E=E5=9B=BD=E6=97=B6=E9=97=B4=E6=9D=A5?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6=E3=80=81=E5=B9=B6=E6=8A=8A=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=97=B6=E9=97=B4=E6=94=B9=E6=88=90=E7=BE=8E=E5=9B=BD?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/purchase/index.vue | 43 +++++++++++++++++++++++----------------- utils/class/date.js | 27 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/pages/purchase/index.vue b/pages/purchase/index.vue index 2a2c900..ce98fe6 100644 --- a/pages/purchase/index.vue +++ b/pages/purchase/index.vue @@ -47,23 +47,17 @@ {{ $t("purchase.a2") }} - {{ - detail.expected_time_online - }} + {{convertTo12HourFormat(detail.expected_time_online)}} {{ $t("purchase.a3") }} - {{ - detail.start_subscription_time - }} + {{convertTo12HourFormat(detail.start_subscription_time)}} {{ $t("purchase.a4") }} - {{ - detail.end_subscription_time - }} + {{convertTo12HourFormat(detail.end_subscription_time)}} @@ -71,7 +65,7 @@ {{ $t("purchase.a5") }} - {{ timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown") }}:{{ days }}{{$t("purchase.day")}}{{ hours }}:{{ minutes }}:{{ seconds }} + {{ timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown") }}:{{ hours }}:{{ minutes }}:{{ seconds }} {{ $t("purchase.a1") }} start && now < end) { + }else if (newYorkTime > start && newYorkTime < end) { this.timerbool = true - this.remainingSeconds = Math.floor((end - now) / 1000); + this.remainingSeconds = Math.floor((end - newYorkTime) / 1000); this.startTimer() } }); @@ -374,10 +381,10 @@ export default { updateDisplay() { const seconds = this.remainingSeconds % 60; const minutes = Math.floor(this.remainingSeconds / 60) % 60; - const hours = Math.floor(this.remainingSeconds / 3600) % 24; - const days = Math.floor(this.remainingSeconds / 86400); + const hours = Math.floor(this.remainingSeconds / 3600); + // const days = Math.floor(this.remainingSeconds / 86400); - this.days = days; + // this.days = days; this.hours = this.padZero(hours); this.minutes = this.padZero(minutes); this.seconds = this.padZero(seconds); diff --git a/utils/class/date.js b/utils/class/date.js index 3ae9a7a..bacf61b 100644 --- a/utils/class/date.js +++ b/utils/class/date.js @@ -113,6 +113,29 @@ function parseTime(time, isOffset = false, cformat = null) { return result; } +/** + * 接口时间转换成12进制 + * @param {string|number} dateTimeStr 接口返回的时间和日期 + */ +function convertTo12HourFormat(dateTimeStr) { + // 解析输入的日期时间字符串 + const date = new Date(dateTimeStr.replace(' ', 'T')); // 使用 T 将字符串转换为 ISO 格式 + + // 获取各个部分 + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份要加1,并填充为2位 + const day = String(date.getDate()).padStart(2, '0'); // 填充为2位 + let hours = date.getHours(); + const minutes = String(date.getMinutes()).padStart(2, '0'); // 填充为2位 + const seconds = String(date.getSeconds()).padStart(2, '0'); // 填充为2位 + + // 计算12小时制的小时和 AM/PM + const ampm = hours >= 12 ? 'PM' : 'AM';//PM代表下午,AM代表上午。 + // hours = String(hours % 12 || 12).padStart(2, '0'); // 0转换为12 + + // 格式化输出 + return `${day}-${month}-${year} ${hours}:${minutes}:${seconds} ${ampm}`; +} /** @@ -153,10 +176,12 @@ Object.assign(Date, { time2Date, parseTime, pubTime, + convertTo12HourFormat }); export default{ time2Date, parseTime, - pubTime + pubTime, + convertTo12HourFormat }