fix: date format for chat item (#3436)
This commit is contained in:
parent
ed584b898a
commit
486c09ac9b
@ -1,17 +1,32 @@
|
|||||||
export const isToday = (timestamp: number) => {
|
export const isToday = (timestamp: number) => {
|
||||||
const today = new Date()
|
const today = new Date()
|
||||||
return today.setHours(0, 0, 0, 0) == new Date(timestamp).setHours(0, 0, 0, 0)
|
return today.setHours(0, 0, 0, 0) === new Date(timestamp).setHours(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayDate = (timestamp?: string | number | Date) => {
|
export const displayDate = (timestamp?: string | number | Date) => {
|
||||||
if (!timestamp) return 'N/A'
|
if (!timestamp) return 'N/A'
|
||||||
|
|
||||||
let displayDate = new Date(timestamp).toLocaleString()
|
const date = new Date(timestamp)
|
||||||
if (typeof timestamp === 'number' && isToday(timestamp)) {
|
|
||||||
displayDate = new Date(timestamp).toLocaleTimeString(undefined, {
|
let displayDate = `${date.toLocaleDateString(undefined, {
|
||||||
|
day: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
})}, ${date.toLocaleTimeString(undefined, {
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: true,
|
||||||
|
})}`
|
||||||
|
|
||||||
|
if (typeof timestamp === 'number' && isToday(timestamp)) {
|
||||||
|
displayDate = date.toLocaleTimeString(undefined, {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return displayDate
|
return displayDate
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user