1 var nowDate = new Date(); 2 alert("当前时间为:"+nowDate);//当前时间为:Fri Feb 23 2018 14:16:31 GMT+0800 (中国标准时间) 3 alert("当前毫秒为:"+nowDate.getTime());//当前毫秒为:1519366591738 4 5 var myDate = new Date(nowDate.getTime()); 6 7 alert(myDate.toLocaleString());//转换成本地时间 2018/2/23 下午2:16:31 8 var year = myDate.getFullYear();//年 9 var month = myDate.getMonth()>8 ? myDate.getMonth()+1 : ‘0‘+(myDate.getMonth()+1);//月 10 var day = myDate.getDate()>9 ? myDate.getDate() : ‘0‘+myDate.getDate();//日 11 var hour = myDate.getHours()>9 ? myDate.getHours() : ‘0‘+myDate.getHours();//时 12 var minute = myDate.getMinutes()>9 ? myDate.getMinutes() : ‘0‘+myDate.getMinutes();//分 13 var second = myDate.getSeconds()>9 ? myDate.getSeconds() : ‘0‘+myDate.getSeconds();//秒 14 15 alert(year +‘-‘+ month +‘-‘ +day +‘ ‘+ hour +‘:‘+ minute +‘:‘+ second) ;//得到指定格式 2018-02-23 14:16:31