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