javascript操作unix时间戳10位转换成通用时间(yyyy-MM-dd HH:mm:ss)
//时间戳转换成通用时间 function js_date_time(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 monthStr = month; if (month < 10) monthStr = "0" + month; var dayStr = day; if (day < 10) dayStr = "0" + day; var hourStr = hour; if (hour < 10) hourStr = "0" + hour; var minuteStr = minute; if (minute < 10) minuteStr = "0" + minute; var secondStr = second; if (second < 10) secondStr = "0" + second; var now = new Date(); var now_new = Date.parse(now.toDateString()); //typescript转换写法 var milliseconds = now_new - dateTime; var timeSpanStr = year + '-' + monthStr + '-' + dayStr + ' ' + hourStr + ':' + minuteStr + ':' + secondStr; return timeSpanStr; }
文章评论