From 0d21bc334ff8e175c6bd409f21b3ef8bbb7b2c87 Mon Sep 17 00:00:00 2001 From: dongyukun <1208714201@qq.com> Date: 星期五, 08 十一月 2024 10:58:00 +0800 Subject: [PATCH] 查询时间秒位格式化 默认时间值格式化bug --- src/utils/dateUtil.ts | 14 ++++++++++++++ src/views/data/point/DaPointChart.vue | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/utils/dateUtil.ts b/src/utils/dateUtil.ts index 658f0a1..a136ed7 100644 --- a/src/utils/dateUtil.ts +++ b/src/utils/dateUtil.ts @@ -38,3 +38,17 @@ if (second < 10) { second = '0' + second } return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second } +export function getYMDHM0 (timestamp: number | string | Date) { + const time = new Date(timestamp) + const year = time.getFullYear() + let month = time.getMonth() + 1 + '' + let date = time.getDate() + '' + let hours = time.getHours() + '' + let minute = time.getMinutes() + '' + + if (month < 10) { month = '0' + month } + if (date < 10) { date = '0' + date } + if (hours < 10) { hours = '0' + hours } + if (minute < 10) { minute = '0' + minute } + return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + '00' +} diff --git a/src/views/data/point/DaPointChart.vue b/src/views/data/point/DaPointChart.vue index 6b4d88f..e496d98 100644 --- a/src/views/data/point/DaPointChart.vue +++ b/src/views/data/point/DaPointChart.vue @@ -24,8 +24,8 @@ <el-date-picker size="mini" v-model="dataForm.endTime" - format="YYYY-MM-DD HH:mm:ss" - value-format="YYYY-MM-DD HH:mm:ss" + format="YYYY-MM-DD HH:mm:00" + value-format="YYYY-MM-DD HH:mm:00" type="datetime" :clearable="false" placeholder="选择日期时间"/> @@ -53,7 +53,7 @@ import {ref} from 'vue'; import * as echarts from 'echarts'; import * as DaPoint from '@/api/data/da/point/daPointChart' - import {getYMDHMS} from "@/utils/dateUtil" + import {getYMDHM0} from "@/utils/dateUtil" import download from "@/utils/download"; const message = useMessage() // 消息弹窗 const visible = ref(false); @@ -69,7 +69,7 @@ pointNo: "", pointName: "", pointTypeName: "", - startTime: getYMDHMS(new Date() - 60 * 60 * 1000), + startTime: getYMDHM0(new Date() - 60 * 60 * 1000), endTime: "", }); -- Gitblit v1.9.3