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

后端 未结 8 1056
轻奢々
轻奢々 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:52

    using HH:mm will convert 12 hrs format to 24hrs while using hh:mm will convert 12hrs format

    moment("12:15 PM").format("HH:mm")
    
    0 讨论(0)
  • 2021-02-01 01:54

    var today = new Date();
    let options = {  
        hour: "2-digit", minute: "2-digit"  
    };  
    console.log(today.toLocaleTimeString("en-us", options));

    0 讨论(0)
提交回复
热议问题