Commit 9571389a by GiottoMaster

update

parent 978199b8
......@@ -37,24 +37,33 @@ export const timestempToDate = (timestamp: number, n: string = '-') => {
return `${year}${n}${month}${n}${day} ${hour}:${minute}`
}
export function timestampToDate2(timestamp: number) {
const date = new Date(timestamp + 3600000 * 9)
const year = date.getUTCFullYear() // 获取年份
let month = date.getUTCMonth() + 1 // 获取月份,需要+1因为月份从0开始
let day = date.getUTCDate() // 获取日
let hours = date.getUTCHours() // 获取小时
let minutes = date.getUTCMinutes() // 获取分钟
let seconds = date.getUTCSeconds() // 获取秒钟
export function timestampToDate2(input: number | string): string {
let date: Date
if (typeof input === 'number') {
// 判断是否为秒级时间戳(小于13位)
if (input.toString().length <= 10) {
input = input * 1000
}
date = new Date(input + 3600000 * 9) // 加 9 小时
} else if (typeof input === 'string') {
const parsed = new Date(input)
if (isNaN(parsed.getTime())) {
return 'Invalid Date'
}
date = new Date(parsed.getTime() + 3600000 * 9)
} else {
return 'Invalid Input'
}
// 格式化月份、日期、小时、分钟和秒
month = month < 10 ? '0' + month : month
day = day < 10 ? '0' + day : day
hours = hours < 10 ? '0' + hours : hours
minutes = minutes < 10 ? '0' + minutes : minutes
seconds = seconds < 10 ? '0' + seconds : seconds
const year = date.getUTCFullYear()
const month = String(date.getUTCMonth() + 1).padStart(2, '0')
const day = String(date.getUTCDate()).padStart(2, '0')
const hours = String(date.getUTCHours()).padStart(2, '0')
const minutes = String(date.getUTCMinutes()).padStart(2, '0')
const seconds = String(date.getUTCSeconds()).padStart(2, '0')
// 组合成日期时间字符串
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
// 获取股票颜色
......
......@@ -3,6 +3,7 @@ import { useI18n } from 'vue-i18n'
import { ref } from 'vue'
import { getUserMessageApi, getUserMessageDetailApi } from '@/api/message'
import { onShow } from '@dcloudio/uni-app'
import { timestampToDate2 } from '@/common/common'
const { t } = useI18n()
const UserMessageList = ref([])
......@@ -21,35 +22,35 @@ const getUserMessageDetail = async () => {
await getUserMessageDetailApi()
}
const getData = (dataString: any) => {
const time = new Date(dataString * 1000)
const year = time.getFullYear()
const month = time.getMonth() + 1
const day = time.getDate()
const hour = time.getHours()
const minute = time.getMinutes()
const second = time.getSeconds()
return (
year +
'-' +
(month < 10 ? '0' + month : month) +
'-' +
(day < 10 ? '0' + day : day) +
' ' +
(hour < 10 ? '0' + hour : hour) +
':' +
(minute < 10 ? '0' + minute : minute) +
':' +
(second < 10 ? '0' + second : second)
)
}
// const getData = (dataString: any) => {
// const time = new Date(dataString * 1000)
// const year = time.getFullYear()
// const month = time.getMonth() + 1
// const day = time.getDate()
// const hour = time.getHours()
// const minute = time.getMinutes()
// const second = time.getSeconds()
// return (
// year +
// '-' +
// (month < 10 ? '0' + month : month) +
// '-' +
// (day < 10 ? '0' + day : day) +
// ' ' +
// (hour < 10 ? '0' + hour : hour) +
// ':' +
// (minute < 10 ? '0' + minute : minute) +
// ':' +
// (second < 10 ? '0' + second : second)
// )
// }
</script>
<template>
<Navigater :title="t('message.xiaoxi')" />
<view>
<scroll-view scroll-y :style="{ height: 'calc(100vh - 48px)' }">
<view v-for="(item, index) in UserMessageList" :key="index">
<view class="createtime">{{ getData(item.createtime) }}</view>
<view class="createtime">{{ timestampToDate2(item.createtime) }}</view>
<view class="content">{{ item.content }}</view>
</view>
<NotData v-if="UserMessageList.length === 0" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment