微信小程序 时间戳 转化为 日期格式

时间:2023-03-08 18:20:01

util.js  :

function transTime(unixtime) {
var dateTime = new Date(parseInt(unixtime) * 1000)
var year = dateTime.getFullYear();
var month = dateTime.getMonth() + 1;
var day = dateTime.getDate();
var hour = dateTime.getHours();
var minute = dateTime.getMinutes();
var second = dateTime.getSeconds();
var now = new Date();
var now_new = Date.parse(now.toDateString());
var milliseconds = now_new - dateTime;
var timeSpanStr = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
return timeSpanStr;
} module.exports = {
transTime: transTime
}

js文件:

// 引入
var util = require('../../utils/util.js'); // 使用
console.log(util.transTime(value));

1