gpt4 book ai didi

javascript - Moment JS 日期和时间到 moment.js 中的时间戳

转载 作者:行者123 更新时间:2023-11-30 07:52:06 29 4
gpt4 key购买 nike

我得到一个文本值,它的格式如下:“9/19/2018 10:00 AM”。您将如何使用 moment.js 或仅使用 javascript 将其转换为纪元时间戳?

示例:

console.log(moment('4/17/2018 10:00 AM', 'mm/dd/yyyy hh:mm a').format('x'));

最佳答案

使用日期字符串创建日期对象,然后使用对象的getTime() 方法。

date = new Date("9/19/2018 10:00 AM");
console.log(date.getTime())

关于javascript - Moment JS 日期和时间到 moment.js 中的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50726254/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com