<script type="text/javascript"> var strDate = ''; $(function(){ // 获取时间戳 时间戳为10位需*1000,时间戳为13位的话则不用 var nowDate = new Date().getTime(); //1564624526889 // 调用封装好的时间转换方法 timestampToTime(nowDate); }()) function timestampToTime(timestamp) { var date = new Date(timestamp); 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>
标签:jquery,10,getMinutes,getSeconds,strDate,var,date,年月日,时分秒 From: https://www.cnblogs.com/fkbzr1998/p/16865583.html