在埋 id 時,很常使用的方法:
Date 物件是基於世界標準時間(UTC) 1970 年 1 月 1 日開始的毫秒數值來儲存時間。
所以可以透過 new Date().getTime()
的方式來當成 id 使用。
//建立 Date() 物件後使用 getTime() 取得時間
//getTime() 會取出 (由 1970年1月1日零時零分計起到目前時間)
let id = new Date().getTime();
console.log(id)//1629966889412 (每毫秒都不同,所以歡迎自行貼到 CodePen 觀看)
JS
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up