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

Method code for converting JS timestamp to normal time format

小云云
Release: 2018-03-08 15:51:23
Original
2622 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template