Home > Article > Web Front-end > Method code for converting JS timestamp to normal time format
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 += '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; }
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!