JavaScript 獲取當前毫秒時間戳
阿新 • • 發佈:2019-01-02
function getTime(){
//第一種方法 1498627266000
var timestamp1 =Date.parse(new Date());
console.log(timestamp1);
//第二種方法 1498627266558
var timestamp2 =(new Date()).valueOf();
console.log(timestamp2);
//第三種方法 1498627266558
var timestamp3 =new Date().getTime();
console.log(timestamp3);
var myDate = new Date();
console.log(myDate.getFullYear()); //獲取完整的年份(4位,1970-????)
console.log(myDate.getMonth()); //獲取當前月份(0-11,0代表1月)
console.log(myDate.getDate()); //獲取當前日(1-31)
console.log(myDate.getDay()); //獲取當前星期X(0-6,0代表星期天)
console.log(myDate.getTime()); //獲取當前時間(從1970.1.1開始的毫秒數)
console.log(myDate.getHours()); //獲取當前小時數(0-23)
console.log(myDate.getMinutes()); //獲取當前分鐘數(0-59)
console.log(myDate.getSeconds()); //獲取當前秒數(0-59)
console.log(myDate.getMilliseconds()); //獲取當前毫秒數(0-999)
console.log(myDate.toLocaleDateString()); //獲取當前日期
console.log(myDate.toLocaleTimeString()); //獲取當前時間
console.log(myDate.toLocaleString()); //獲取日期與時間
}
//第一種方法 1498627266000
var timestamp1 =Date.parse(new Date());
console.log(timestamp1);
//第二種方法 1498627266558
var timestamp2 =(new Date()).valueOf();
console.log(timestamp2);
//第三種方法 1498627266558
var timestamp3 =new Date().getTime();
console.log(timestamp3);
var myDate = new Date();
console.log(myDate.getFullYear()); //獲取完整的年份(4位,1970-????)
console.log(myDate.getMonth()); //獲取當前月份(0-11,0代表1月)
console.log(myDate.getDate()); //獲取當前日(1-31)
console.log(myDate.getDay()); //獲取當前星期X(0-6,0代表星期天)
console.log(myDate.getTime()); //獲取當前時間(從1970.1.1開始的毫秒數)
console.log(myDate.getHours()); //獲取當前小時數(0-23)
console.log(myDate.getMinutes()); //獲取當前分鐘數(0-59)
console.log(myDate.getSeconds()); //獲取當前秒數(0-59)
console.log(myDate.getMilliseconds()); //獲取當前毫秒數(0-999)
console.log(myDate.toLocaleDateString()); //獲取當前日期
console.log(myDate.toLocaleTimeString()); //獲取當前時間
console.log(myDate.toLocaleString()); //獲取日期與時間
}