Browse Source

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

master
liaoxinyu 1 year ago
parent
commit
a1e74c07fe
  1. 27
      src/utils/class/date.js
  2. 2
      src/views/contract/index.vue
  3. 40
      src/views/purchase/index.vue

27
src/utils/class/date.js

@ -215,6 +215,29 @@ function parseTime(time, isOffset = false, cformat = null) {
return result; 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}`;
}
/** /**
* 发布日期的特定显示方式 * 发布日期的特定显示方式
@ -254,10 +277,12 @@ Object.assign(Date, {
time2Date, time2Date,
parseTime, parseTime,
pubTime, pubTime,
convertTo12HourFormat
}); });
export default{ export default{
time2Date, time2Date,
parseTime, parseTime,
pubTime pubTime,
convertTo12HourFormat
} }

2
src/views/contract/index.vue

@ -101,7 +101,7 @@
<div style="margin-left: 10px;">{{ item.symbol }}/{{ parent.coin_name }}</div> <div style="margin-left: 10px;">{{ item.symbol }}/{{ parent.coin_name }}</div>
</div> </div>
</div> </div>
<div class="text-right width-32">{{ item.close }}</div> <div class="text-right width-32">{{ item.price }}</div>
<div class="text-right width-32" :class="item.increase < 0 ? 'decreace' : 'increase'">{{ item.increaseStr }}</div> <div class="text-right width-32" :class="item.increase < 0 ? 'decreace' : 'increase'">{{ item.increaseStr }}</div>
</td> </td>
<!-- <td class="w-7/24 text-right" >{{ item.close }}</td> <!-- <td class="w-7/24 text-right" >{{ item.close }}</td>

40
src/views/purchase/index.vue

@ -26,7 +26,7 @@
</div> </div>
<div class="txt"> <div class="txt">
<!-- {{ parseTime(detail.expected_time_online) }} --> <!-- {{ parseTime(detail.expected_time_online) }} -->
{{ detail.expected_time_online }} {{ convertTo12HourFormat(detail.expected_time_online) }}
</div> </div>
</li> </li>
<li class="mt-3"> <li class="mt-3">
@ -35,7 +35,7 @@
</div> </div>
<div class="txt"> <div class="txt">
<!-- {{ parseTime(detail.start_subscription_time) }} --> <!-- {{ parseTime(detail.start_subscription_time) }} -->
{{ detail.start_subscription_time }} {{ convertTo12HourFormat(detail.start_subscription_time) }}
</div> </div>
</li> </li>
<li class="mt-3"> <li class="mt-3">
@ -44,7 +44,7 @@
</div> </div>
<div class="txt"> <div class="txt">
<!-- {{ parseTime(detail.end_subscription_time) }} --> <!-- {{ parseTime(detail.end_subscription_time) }} -->
{{ detail.end_subscription_time }} {{ convertTo12HourFormat(detail.end_subscription_time) }}
</div> </div>
</li> </li>
</ul> </ul>
@ -52,7 +52,7 @@
<div <div
class="col-6 d-flex flex-column justify-content-end align-items-start" class="col-6 d-flex flex-column justify-content-end align-items-start"
> >
<div style="margin-bottom: 20px;">{{timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown")}}: <span style="margin-right: 10px;">{{ days }}{{$t("purchase.day")}}</span><span>{{ hours }}:</span><span>{{ minutes }}:</span><span>{{ seconds }}</span></div> <div style="margin-bottom: 20px;">{{timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown")}}: <span>{{ hours }}:</span><span>{{ minutes }}:</span><span>{{ seconds }}</span></div>
<div class="input-group mb-3"> <div class="input-group mb-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
<el-dropdown> <el-dropdown>
@ -309,6 +309,7 @@
</template> </template>
<script> <script>
import date from "@/utils/class/date.js";
import Subscride from "@/api/subscride"; import Subscride from "@/api/subscride";
import Wallet from "@/api/wallet"; import Wallet from "@/api/wallet";
export default { export default {
@ -361,7 +362,8 @@ export default {
}, },
}, },
methods: { methods: {
// convertTo12HourFormat: date.convertTo12HourFormat,
//
seek(item) { seek(item) {
return !this.isCondition || item.coin_name === this.coinName; return !this.isCondition || item.coin_name === this.coinName;
}, },
@ -397,14 +399,26 @@ export default {
// //
const start = new Date(this.detail.start_subscription_time).getTime(); const start = new Date(this.detail.start_subscription_time).getTime();
const end = new Date(this.detail.end_subscription_time).getTime(); const end = new Date(this.detail.end_subscription_time).getTime();
const now = Date.now(); const now = new Date();
if(now < start && now < end){ 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.timerbool = false
this.remainingSeconds = Math.floor((start - now) / 1000); this.remainingSeconds = Math.floor((start - newYorkTime) / 1000);
this.startTimer() this.startTimer()
}else if (now > start && now < end) { }else if (newYorkTime > start && newYorkTime < end) {
this.timerbool = true this.timerbool = true
this.remainingSeconds = Math.floor((end - now) / 1000); this.remainingSeconds = Math.floor((end - newYorkTime) / 1000);
this.startTimer() this.startTimer()
} }
}); });
@ -506,10 +520,10 @@ export default {
updateDisplay() { updateDisplay() {
const seconds = this.remainingSeconds % 60; const seconds = this.remainingSeconds % 60;
const minutes = Math.floor(this.remainingSeconds / 60) % 60; const minutes = Math.floor(this.remainingSeconds / 60) % 60;
const hours = Math.floor(this.remainingSeconds / 3600) % 24; const hours = Math.floor(this.remainingSeconds / 3600);
const days = Math.floor(this.remainingSeconds / 86400); // const days = Math.floor(this.remainingSeconds / 86400);
this.days = days; // this.days = days;
this.hours = this.padZero(hours); this.hours = this.padZero(hours);
this.minutes = this.padZero(minutes); this.minutes = this.padZero(minutes);
this.seconds = this.padZero(seconds); this.seconds = this.padZero(seconds);

Loading…
Cancel
Save