JS将毫秒时间戳转换成合适的时间字符串

function convertTimestampToString(timestamp)
{
    var now = new Date();
    var yy = now.getFullYear();      //年
    var mm = now.getMonth() + 1;     //月
    var dd = now.getDate();          //日
    var hh = now.getHours();         //时
    var ii = now.getMinutes();       //分
    var ss = now.getSeconds();       //秒

    var nowTimestamp = now.getTime();

    var d = new Date(timestamp);    //根据时间戳生成的时间对象
    var tyear = d.getFullYear();
    var tmonth = d.getMonth() + 1;
    var tday = d.getDate();
    var week = d.getDay();
    var thour = d.getHours();
    var tminute = d.getMinutes();
    var tseconds = d.getSeconds();

    var diffTime = nowTimestamp - timestamp;
    if (tyear < yy) {
        if (tmonth < 10) {
            tmonth = '0' + tmonth;
        }
        if (tday < 10) {
            tday = '0' + tday;
        }
      

你可能感兴趣的:(JS将毫秒时间戳转换成合适的时间字符串)