2023-12-18 03:12:07 +00:00
|
|
|
// 处理时间
|
|
|
|
export const handleDate = (dateTimeStamp = new Date()) => {
|
|
|
|
dateTimeStamp = dateTimeStamp ? dateTimeStamp : null
|
|
|
|
var timestamp = new Date(dateTimeStamp)
|
|
|
|
timestamp = timestamp.getTime()
|
|
|
|
var minute = 1000 * 60
|
|
|
|
var hour = minute * 60
|
|
|
|
var day = hour * 24
|
|
|
|
var now = new Date().getTime()
|
|
|
|
var diffValue = now - timestamp
|
|
|
|
var result
|
|
|
|
if (diffValue < 0) return
|
|
|
|
|
|
|
|
var dayC = diffValue / day
|
|
|
|
var hourC = diffValue / (hour + 1)
|
|
|
|
var minC = diffValue / minute
|
|
|
|
if (dayC >= 7) {
|
|
|
|
let date = new Date(timestamp)
|
|
|
|
let Y = date.getFullYear() + "-"
|
|
|
|
let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"
|
|
|
|
let D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "
|
|
|
|
let h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"
|
|
|
|
let m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
|
|
|
|
result = "" + Y + M + D + h + m
|
|
|
|
} else if (dayC >= 1) result = "" + Math.round(dayC) + "天前"
|
|
|
|
else if (hourC >= 1) result = "" + Math.round(hourC) + "小时前"
|
|
|
|
else if (minC >= 1) result = "" + Math.round(minC) + "分钟前"
|
|
|
|
else result = "刚刚"
|
|
|
|
|
|
|
|
return result
|
2023-12-18 11:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const timestampToDate = (timestamp) => {
|
|
|
|
var date = new Date(timestamp);
|
|
|
|
var year = date.getFullYear();
|
|
|
|
var month = ("0" + (date.getMonth() + 1)).slice(-2); // Months are zero based. Add leading 0.
|
|
|
|
var day = ("0" + date.getDate()).slice(-2); // Add leading 0.
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
}
|