您的位置:首页 > Web前端 > JavaScript

JS 日期与时间戳相互转化

2016-06-21 16:50 295 查看
1、日期格式转时间戳 

function getTimestamp(time)
{
return Date.parse(new Date(time));
}


2、时间戳转日期格式 

function transformPHPTime(time)
{
    var date = new Date(time * 1000);
    
Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();

    return Y+M+D+h+m+s;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: