momentjs - how do I build moment from date and tim

2019-02-12 02:00发布

If I have given date string MM-DD-YYYY and time string HH:mm A or H:m a, how do I build a moment object? I tried moment('MM-DD-YYYY HH:mm A') which did not work.

2条回答
萌系小妹纸
2楼-- · 2019-02-12 02:20

To create a moment object of your desired time, do the following:

moment('05-17-2018 23:40 AM', 'MM-DD-YYYY hh:mm A')

In this case '05-17-2018 23:40 AM' is the desired time.

查看更多
等我变得足够好
3楼-- · 2019-02-12 02:31

Try using the format (second) parameter moment("12-25-1995", "MM-DD-YYYY");

For details see http://momentjs.com/docs/#/parsing/string-format/

查看更多
登录 后发表回答