Browse Source

修改时间需要是美国时间来倒计时、并把其他时间改成美国时间形式

master
liaoxinyu 1 year ago
parent
commit
daf3696fba
  1. 43
      pages/purchase/index.vue
  2. 27
      utils/class/date.js

43
pages/purchase/index.vue

@ -47,23 +47,17 @@
<vue class="m-b-xs"><img :src="detail.icon" style="width: 30px;" /></vue>
<view class="m-b-xs">
<view class="label fn-10">{{ $t("purchase.a2") }}</view>
<view class="color-light">{{
detail.expected_time_online
}}
<view class="color-light">{{convertTo12HourFormat(detail.expected_time_online)}}
</view>
</view>
<view class="m-b-xs">
<view class="label fn-10">{{ $t("purchase.a3") }}</view>
<view class="color-light">{{
detail.start_subscription_time
}}
<view class="color-light">{{convertTo12HourFormat(detail.start_subscription_time)}}
</view>
</view>
<view class="m-b-xs">
<view class="label fn-10">{{ $t("purchase.a4") }}</view>
<view class="color-light">{{
detail.end_subscription_time
}}
<view class="color-light">{{convertTo12HourFormat(detail.end_subscription_time)}}
</view>
</view>
</view>
@ -71,7 +65,7 @@
<!-- 申购 -->
<view class="bg-panel-3 p-md box-shadow">
<view class="title p-b-xs border-b">{{ $t("purchase.a5") }}</view>
<view class="title border-b" style="padding:10px 0px">{{ timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown") }}<span style="margin-right: 7px;">{{ days }}{{$t("purchase.day")}}</span><span>{{ hours }}:</span><span>{{ minutes }}:</span><span>{{ seconds }}</span></view>
<view class="title border-b" style="padding:10px 0px">{{ timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown") }}<span>{{ hours }}:</span><span>{{ minutes }}:</span><span>{{ seconds }}</span></view>
<view class="m-y-md">
<view class="label">{{ $t("purchase.a1") }}</view>
<v-picker
@ -244,6 +238,7 @@ export default {
...mapGetters(['themeStyle'])
},
methods: {
convertTo12HourFormat: date.convertTo12HourFormat,
omitTo(num, idx) {
if (!num) return 0;
return math.omitTo(num, idx);
@ -264,14 +259,26 @@ export default {
//
const start = new Date(this.detail.start_subscription_time).getTime();
const end = new Date(this.detail.end_subscription_time).getTime();
const now = Date.now();
if(now < start && now < end){
const now = new Date();
const options = {
timeZone: 'America/New_York', //
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false // 使24
};
const newYorkTime = new Date(now.toLocaleString('en-US', options)).getTime();
if(newYorkTime < start && newYorkTime < end){
this.timerbool = false
this.remainingSeconds = Math.floor((start - now) / 1000);
this.remainingSeconds = Math.floor((start - newYorkTime) / 1000);
this.startTimer()
}else if (now > 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);

27
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
}

Loading…
Cancel
Save