从纪元计算毫秒 [英] Calculating milliseconds from epoch

查看:10
本文介绍了从纪元计算毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我有: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对象

的技术(大多数浏览器都支持,以及NodeJS)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆