Convert 12 hour (AM/PM) string to 24 Date object using moment js

后端 未结 8 1197
轻奢々
轻奢々 2021-02-01 01:26

I have a output resulting from a timepicker giving 12 hour format of time.

Eg : \"1:45 AM (or) \"12:15 PM\" as **string**

Is there a way to par

8条回答
  •  感情败类
    2021-02-01 01:44

    Just a little conversation "2 PM" to "14.00"

    const number = moment("02:00 PM", ["h:mm A"]).format("HH:mm");
    cosole.log(number); // "14.00"
    

    "14.00" to "2 PM"

    const number = moment("14.00", ["HH.mm"]).format("hh:mm a");
    cosole.log(number); // "02:00 pm"
    

提交回复
热议问题