From a1e74c07fe4d4c677b405d5defd502eda243c1e6 Mon Sep 17 00:00:00 2001 From: liaoxinyu Date: Tue, 11 Mar 2025 19:18:28 +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 --- src/utils/class/date.js | 27 +++++++++++++++++++++++- src/views/contract/index.vue | 2 +- src/views/purchase/index.vue | 40 ++++++++++++++++++++++++------------ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/utils/class/date.js b/src/utils/class/date.js index 529fb78..72b7ef7 100644 --- a/src/utils/class/date.js +++ b/src/utils/class/date.js @@ -215,6 +215,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}`; +} /** * 发布日期的特定显示方式, @@ -254,10 +277,12 @@ Object.assign(Date, { time2Date, parseTime, pubTime, + convertTo12HourFormat }); export default{ time2Date, parseTime, - pubTime + pubTime, + convertTo12HourFormat } \ No newline at end of file diff --git a/src/views/contract/index.vue b/src/views/contract/index.vue index b69064d..f76e68a 100644 --- a/src/views/contract/index.vue +++ b/src/views/contract/index.vue @@ -101,7 +101,7 @@
{{ item.symbol }}/{{ parent.coin_name }}
-
{{ item.close }}
+
{{ item.price }}
{{ item.increaseStr }}
- {{ detail.expected_time_online }} + {{ convertTo12HourFormat(detail.expected_time_online) }}
  • @@ -35,7 +35,7 @@
    - {{ detail.start_subscription_time }} + {{ convertTo12HourFormat(detail.start_subscription_time) }}
  • @@ -44,7 +44,7 @@
    - {{ detail.end_subscription_time }} + {{ convertTo12HourFormat(detail.end_subscription_time) }}
  • @@ -52,7 +52,7 @@
    -
    {{timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown")}}: {{ days }}{{$t("purchase.day")}}{{ hours }}:{{ minutes }}:{{ seconds }}
    +
    {{timerbool?$t("purchase.Countdown1"):$t("purchase.Countdown")}}: {{ hours }}:{{ minutes }}:{{ seconds }}
    @@ -309,6 +309,7 @@