[javascript] moment.js 24h format

How do I display my time in 24h format instead of 12?

I am using moment.js.

I am pretty sure that these lines could have something to do with it.

   meridiem : function (hours, minutes, isLower) {
        if (hours > 11) {
            return isLower ? 'pm' : 'PM';
        } else {
            return isLower ? 'am' : 'AM';
        }
    },

How to change it?

This question is related to javascript momentjs

The answer is


_x000D_
_x000D_
//Format 24H use HH:mm_x000D_
let currentDate = moment().format('YYYY-MM-DD HH:mm')_x000D_
console.log(currentDate)_x000D_
_x000D_
//example of current time with defined Time zone +1_x000D_
let currentDateTm = moment().utcOffset('+0100').format('YYYY-MM-DD HH:mm')_x000D_
console.log(currentDateTm)
_x000D_
<script src="https://momentjs.com/downloads/moment.js"></script>
_x000D_
_x000D_
_x000D_


moment("01:15:00 PM", "h:mm:ss A").format("HH:mm:ss")
**o/p: 13:15:00 **

it will give convert 24 hrs format to 12 hrs format.


You can use

 moment("15", "hh").format('LT') 

to convert the time to 12 hours format like this 3:00 PM


HH used 24 hour format while hh used for 12 format


Use this to get time from 00:00:00 to 23:59:59

If your time is having date from it by using 'LT or LTS'

var now = moment('23:59:59','HHmmss').format("HH:mm:ss")

** https://jsfiddle.net/a7qLhsgz/**


Use H or HH instead of hh. See http://momentjs.com/docs/#/parsing/string-format/


Try: moment({ // Options here }).format('HHmm'). That should give you the time in a 24 hour format.