1、获取当前时间:
格式:yyyy-MM-dd HH:mm:SS
function getFormatDate(){
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
var hour = nowDate.getHours()< 10 ? "0" + nowDate.getHours() : nowDate.getHours();
var minute = nowDate.getMinutes()< 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
var second = nowDate.getSeconds()< 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}
var str = getFormatDate();
console.log(str);
$(".content_list_time").text(str);
2、 获取当前时间时间戳:
(new Date()).getTime()
3、获取并截取时间戳:
var global_time = ((new Date()).getTime() + '').substring(0, 10);
((new Date()).getTime() + '') 是将整形变成字符串。
substring(0, 10) 只用于截取字符串,是从第0个开始截取,截取10个。
作者:inmarry
来源:CSDN
原文:https://blog.csdn.net/inmarry/article/details/80973415