search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[JS] 取得 unix timestamp 的方法

此篇文章瀏覽量: 996
const timestamp1 = Date.now();
const timestamp2 = new Date().getTime();
const timestamp3 = +new Date();
// 以上三種寫法會取得目前的 unix timestamp
console.log(timestamp1 + " " + timestamp2 + " " + timestamp3);
      
const timestamp4 = new Date('2012-06-08').getTime();
const timestamp5 = +new Date('2012-06-08');
// 以上二種寫法會取得特定日期的 unix timestamp
console.log(timestamp4 + " " + timestamp5);

若覺得文章有幫助,請多分享,讓其他同好也能吸收網站技能知識。



熱門推薦

本文由 carlos-studiocom 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦