【问题标题】:moment js time formatting with custom time format as inputs使用自定义时间格式作为输入的时刻 js 时间格式
【发布时间】:2021-06-09 20:30:28
【问题描述】:

输入格式可以是,hh:mm OR hh OR hh:mm:ss OR hh:mm A/hh A/hh:mm:ss 如何将其格式化为与“hh:mm:ss A”格式相同的内联格式。

我们如何使用moment js进行格式化。或者它对于时刻 js 时间格式的输入是不可行的。

【问题讨论】:

    标签: javascript momentjs time-format


    【解决方案1】:

    Format method 是可能的

    DEMO

    import moment from "moment";
    
    let date = new Date();
    let time = date.getTime();
    
    moment(time).format("hh:mm:ss A");
    

    【讨论】:

    • 应用{moment('2020/-0/5-23T23:32:10Z','hh:mm:ss A').format("hh:mm:ss A")时,输出为08:32:10 PM,是否考虑UTC,甚至不确定UTC的正确时间。这是可能的输入之一。
    • @dsi 我很确定您正在解析它,并以应将其解释为的显式格式传递。请改用:moment('2020/-0/5-23T23:32:10Z').format('hh:mm:ss A') -- 但请注意,据我所知,斜杠在 ISO 时间字符串中无效。
    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 2021-07-27
    • 2018-04-01
    • 1970-01-01
    • 2013-11-09
    • 2016-12-26
    • 1970-01-01
    • 2019-05-11
    相关资源
    最近更新 更多