1

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

2
  • Possible duplicate of moment.js 24h format 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. Commented May 11, 2017 at 14:41

1 Answer 1

9

If 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.

Sign up to request clarification or add additional context in comments.

1 Comment

this is what im about to try @adam-beck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.