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
}