I am using jQuery timepicker for displaying 12 hr format time on UI. But internally as data goes to server i have to convert that format into 24 hr format. How can i do this using moment js
Here's how my time shown on display
07:50 PM
I want that to be get converted into in 24 hr format. I'm trying below method but getting same output as shown on UI.
output=moment($(this).val(),"hh:mm").format("HH mm");
Please help me out . Thank you
I am using jQuery timepicker for displaying 12 hr format time on UI. But internally as data goes to server i have to convert that format into 24 hr format. How can i do this using moment js
Here's how my time shown on display
07:50 PM
I want that to be get converted into in 24 hr format. I'm trying below method but getting same output as shown on UI.
output=moment($(this).val(),"hh:mm").format("HH mm");
Please help me out . Thank you
Share Improve this question edited May 11, 2017 at 14:45 Nerdy Sid asked May 11, 2017 at 14:22 Nerdy SidNerdy Sid 3326 silver badges14 bronze badges 2- Possible duplicate of moment.js 24h format – mxr7350 Commented May 11, 2017 at 14:23
-
@mxr7350 OP is formatting the time correctly. They are not creating the correct
moment
object. I don't think this is necessarily a duplicate. – adam-beck Commented May 11, 2017 at 14:41
1 Answer
Reset to default 9If your value is returning 07:50 PM
you need to change the moment
call to
output = moment($(this).val(), 'hh:mm A').format('HH mm');
Notice that I added an A
after the minutes to tell moment to take into account the AM/PM
value that follows the time.