JS时间戳转为正常时间格式的方法代码

小云云
小云云 原创
2018-03-08 15:51:23 2126浏览

本文主要和大家分享JS时间戳转为正常时间格式的方法代码,希望能帮助到大家。

//JS时间戳转为YYYY-MM-DD HH:mm:ss
function exChangeTime(timeStamp){
var str = "";
str += timeStamp.getFullYear() + '-';
timeStamp.getMonth() < 10 ? str += '0' + (timeStamp.getMonth() + 1) + '-' : str += (timeStamp.getMonth() + 1) + '-';
timeStamp.getDate() < 10 ? str += '0' + timeStamp.getDate() + ' ' : str += timeStamp.getDate() + ' ';
timeStamp.getHours() < 10 ? str += '0' + timeStamp.getHours() + ':' : str += timeStamp.getHours() + ':';
timeStamp.getMinutes() < 10 ? str += '0' + timeStamp.getMinutes() + ':' : str += timeStamp.getMinutes() + ':';
timeStamp.getSeconds() < 10 ? str += '0' + timeStamp.getSeconds(): str += timeStamp.getSeconds();
return str;
}

相关推荐:

js时间戳和普通时间相互转换方法代码

js时间戳如何转为时间格式

js时间戳格式化成日期格式的多种方法_javascript技巧

以上就是JS时间戳转为正常时间格式的方法代码的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。