最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Converting 12 hr format to 24 hr format using moment js in Angularjs - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论