Home  >  Article  >  Web Front-end  >  Method code for converting JS timestamp to normal time format

Method code for converting JS timestamp to normal time format

小云云
小云云Original
2018-03-08 15:51:232567browse

This article mainly shares with you the method code for converting JS timestamp to normal time format. I hope it can help you.

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

Related recommendations:

JS timestamp and ordinary time conversion method code

How to convert js timestamp to time format

Multiple ways to format js timestamp into date format_javascript skills

The above is the detailed content of Method code for converting JS timestamp to normal time format. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn