【问题标题】:How to get timestamp for converted i18n date using momentjs如何使用 momentjs 获取转换后的 i18n 日期的时间戳
【发布时间】:2018-08-14 17:07:47
【问题描述】:

我正在使用带有时区的 momentjs。

我已使用 moment.locale('pt'); 将日期转换为 i18n

现在我想获取日期的时间戳。我将日期值作为转换后的 i18n 日期,即Ago 14 2018 22:00

我尝试使用 moment("Ago 14 2018 22:00").tz("Asia/Calcutta").unix() => 这是返回 NaN

但这有效 => moment("Aug 14 2018 22:00").tz("Asia/Calcutta").unix()

那么如何获取转换后的 i18n 日期的时间戳??

这是问题所在:http://jsfiddle.net/uq99udc9/10265/

【问题讨论】:

    标签: internationalization momentjs moment-timezone


    【解决方案1】:

    您需要首先按照momentJS documentation 指定locale。 您还需要确保您拥有该语言环境,如果没有,请导入它。

    这是一个例子:

    moment.locale('fr')
    var date = moment("14 août 2018 10:37", "DD MMM YYYY hh:mm", "fr").format('LLL')
    console.log(date);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/locale/fr.js" charset="UTF-8"></script>

    【讨论】:

    • 是的,葡萄牙语中的 Aug 是 Ago
    • 添加示例。希望这会有所帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多