change time format to 24 hours in javascript

前端 未结 7 936
春和景丽
春和景丽 2020-12-15 23:12

I have a time format like: 12/16/2011 3:49:37 PM and I got this format by:

var newDate = new Date(timeFromat);
timeFormat = newDate.toLocaleString();
         


        
相关标签:
7条回答
  • 2020-12-16 00:02

    use dateObj.toLocaleString([locales[, options]])

    Option 1 - Using locales

    var date = new Date();
    console.log(date.toLocaleString('en-GB'));
    

    Option 2 - Using options

    var options = { hour12: false };
    console.log(date.toLocaleString('en-US', options));
    
    0 讨论(0)
提交回复
热议问题