将UNIX时间戳转换为Luxon.js中的毫秒
我有“ HH:MM”格式的字符串数据,例如05:00。我想要它在毫秒中,例如1800000
console.log(dateTime.fromiso(“ 05:00”)
,我得到以下输出:16545744400000,但是我想要几秒钟的时间,以便我可以将其与A相比,不同的价值。 console.log(dateTime(“ 05:00”))。tomillis();
它带有“未经手的拒绝(TypeError):如果没有'new''。
I have string data in the format "hh:mm" e.g. 05:00. I want it in Milliseconds e.g 1800000
console.log(DateTime.fromISO("05:00")
and i get the following output: 1654574400000 but what i want it in seconds so i can compare it against a different value. I have tried putting .toMillis() at the endconsole.log(DateTime("05:00")).toMillis();
and it comes back with "Unhandled Rejection (TypeError): Class constructor DateTime cannot be invoked without 'new'".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当时间传递到 fromiso 时,使用当前日期。要使时间以毫秒为单位,请将其解析为a datetime 并在一天开始时减去 dateTime
您也可以使用普通JS:
When a time is passed to fromISO, the current date is used. To get the time in milliseconds, parse it to a DateTime and subtract a DateTime for the start of the day, e.g.
You can also use plain JS:
您可以解析
“ 05:00”
作为持续时间
,使用持续时间。fromisotime 那就是:然后使用
as(unit)
:例子:
You can parse
"05:00"
as aDuration
, usingDuration.fromISOTime
that:and then display its value using
as(unit)
:Example: