moment.js 24h format

前端 未结 8 962
無奈伤痛
無奈伤痛 2020-12-01 09:04

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.

<         


        
相关标签:
8条回答
  • 2020-12-01 09:12

    HH used 24 hour format while hh used for 12 format

    0 讨论(0)
  • 2020-12-01 09:18

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

    0 讨论(0)
  • 2020-12-01 09:22
    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.

    0 讨论(0)
  • 2020-12-01 09:23

    You can use

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

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

    0 讨论(0)
  • 2020-12-01 09:27

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

    0 讨论(0)
  • 2020-12-01 09:31

    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/**

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