How do you display JavaScript datetime in 12 hour AM/PM format?

后端 未结 27 3578
慢半拍i
慢半拍i 2020-11-22 02:36

How do you display a JavaScript datetime object in the 12 hour format (AM/PM)?

27条回答
  •  半阙折子戏
    2020-11-22 03:14

    As far as I know, the best way to achieve that without extensions and complex coding is like this:

         date.toLocaleString([], { hour12: true});
    

    Javascript AM/PM Format

    
    
    
        

    Click the button to display the date and time as a string.

    I found this checking this question out.

    How do I use .toLocaleTimeString() without displaying seconds?

提交回复
热议问题