从纪元计算毫秒 [英] Calculating milliseconds from epoch
问题描述
鉴于我有:mm、dd、yy、hh:mm、am/pm,推荐/最简单的方法是将数据从纪元转换为毫秒?
每次我对这个答案点赞时,都会提醒我我的答案实际上并没有回答这个问题.>
OP:如果您可以将字符串解析为以下格式,则可以使用其他答案之一.MM/DD/YYYY HH:MM:SS AM EDT
(指定时区很重要;纪元基于子午线)
let milliseconds = new Date("1/20/1982 5:00 PM EST").getTime()console.log(毫秒);
一些人认为有用的原始答案:另一种不需要实例化Date
对象
var nowEpoch = Date.now();
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Given that I have: mm, dd, yy, hh:mm, am/pm, what is the recommended/easiest way to convert that data into milliseconds from epoch?
Everytime I get an upvote on this answer, I'm reminded that my answer doesn't actually answer the question.
OP: If you can parse your string into the following format, you can use one of the other answers. MM/DD/YYYY HH:MM:SS AM EDT
(It's important to specify the timezone; epoch is based on the meridian)
let milliseconds = new Date("1/20/1982 5:00 PM EST").getTime()
console.log(milliseconds);
Original Answer that some people have found useful:
Another technique (which most browsers support, as well as NodeJS) that doesn't require having to instantiate a Date
object
var nowEpoch = Date.now();
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
这篇关于从纪元计算毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!