Javascript parsing Times without Date

后端 未结 5 2040
轻奢々
轻奢々 2020-12-08 18:22

I need to parse and manipulate Times without Dates in my code. For example i might get the string \"15:00\" from a timepicker. I want to turn this into a Time object of some

5条回答
  •  悲哀的现实
    2020-12-08 19:04

    Here's a moment.js solution for 12 or 24 hour times:

    moment('7:00 am', ['h:m a', 'H:m']); // Wed Dec 30 2015 07:00:00 GMT-0600 (CST)
    moment('17:00', ['h:m a', 'H:m']);   // Wed Dec 30 2015 17:00:00 GMT-0600 (CST)
    moment('17:00 am', ['h:m a', 'H:m']);// Wed Dec 30 2015 17:00:00 GMT-0600 (CST)
    moment('17:00 pm', ['h:m a', 'H:m']);// Wed Dec 30 2015 17:00:00 GMT-0600 (CST)
    

    http://momentjs.com/docs/#/parsing/string-formats/

提交回复
热议问题