我想将当前日期转换为时间戳。假设今天的日期是 26/4/2019 ,那么我就是这样做的。
const current = new Date();
const timestamp = current.getTime();
但这给了我 1556532767266。当我从中获取日期时,它在 UTC 中显示“Mon Apr 26 2019 10:12:47”,在本地显示“Mon Apr 26 26 2019 15:42:47”。但我想在这个“ 2019 年 4 月 26 日星期一 00:00:00 ”,即晚上 12 点
任何人都可以帮助我如何得到这样的。
您可以将小时/分钟/秒设置为 0 和 getTime()
const current = new Date();
current.setHours(0)
current.setMinutes(0)
current.setSeconds(0)
current.setMilliseconds(0)
const timestamp = current.getTime();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句