前端日期格式化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lixu_csdn/article/details/89638330
//xxxx年xx月xx日字符串日期转换 str==》str(2019-04-28==》2019年4月28日)
function timeStamp2String(strDate){
    var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
        function(a) {return parseInt(a, 10) - 1;}).match(/\d+/g) + ')');
    var datetime = new Date();
    datetime.setTime(date);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1;
    var date = datetime.getDate();
    return year + "年" + month + "月" + date+"日";
}

猜你喜欢

转载自blog.csdn.net/lixu_csdn/article/details/89638330