js 时间戳转换为年月日时分秒的格式

2023-02-17,,,,

  <script type="text/javascript">
var strDate = '';
$(function(){
// 获取时间
var nowDate = new Date().getTime(); //1564624526889
// 调用封装好的时间转换方法
timestampToTime(nowDate);
}()) function timestampToTime(timestamp) {
var date = new Date();//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds()); strDate = Y+M+D+h+m+s;
return strDate; }
console.log(strDate) //2019-08-01 09:55:26
</script>

js 时间戳转换为年月日时分秒的格式的相关教程结束。

《js 时间戳转换为年月日时分秒的格式.doc》

下载本文的Word格式文档,以方便收藏与打印。