How format JavaScript Date with regard to the browser culture?

前端 未结 3 1487
走了就别回头了
走了就别回头了 2020-12-04 02:57

I need to format the JavaScript Date object. It should display date and time in short format with regard to the culture that browser is using, for example:

2         


        
3条回答
  •  有刺的猬
    2020-12-04 03:22

    The Date() object will get you the client time (live demo here):

    var now=new Date();
    alert(now.toLocaleString());
    

    JS and jQuery don't have a built in format function. To format it differently use a function like format() (1.2kb) here and then the following code will produce a format like "10/10/2012 8:50pm" :

    var now=new Date();    
    alert( now.format("mm/dd/yy h:MM:ss TT") );
    

提交回复
热议问题