// 传时间戳转年月日时分秒
msToDate(milliseconds) {
var date = new Date(milliseconds)
var year = date.getFullYear();
var month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
var day = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
var hours = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
var minutes = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
var seconds = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
var dateTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds
console.log(dateTime)
return dateTime;
}
// 传时间转时间戳
msToDate(milliseconds) {
var date = new Date(milliseconds)
var dateT
前端js时间戳互转年月日时分秒,前端js两个年月日时分秒时间相减获得时间差,相差几天几月几日几时几分几秒,直接复制即用。
于 2024-05-06 10:09:10 首次发布