您现在的位置是:js时间戳转换

js时间戳转换

分类: Web 日期:2019-09-03点击:1523
//时间戳转换
function timestampToSecond(timestamp) {
    var date = new Date(timestamp);
    h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + '小时';
    m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()+"分";
    s = date.getSeconds();

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

    return Y + M + D + h + m;
}
function timestampToTimeToMonth(timestamp) {
    var date = new Date(timestamp);
    Y = date.getFullYear() + '-';
    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);

    return Y + M;
}

function timestampToTimeToDay(timestamp) {
    var date = new Date(timestamp);
    Y = date.getFullYear() + '-';
    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());

    return Y + M + D;
}
标签: JavaScript

站长简介

    姓名:喻理
    微信:yuli0927
    邮箱:yuli0927@126.com
    不懂业务的运维工程师不是一个好程序员。

分类

最新文章

热门文章

全站标签