Javascript reformat date string

前端 未结 5 1967
再見小時候
再見小時候 2020-12-21 01:14

I have this date fromat:

Mon Feb 02 2015 05:18:44 GMT+0000 (UTC) 

How can I reformat it to something more friendlier such as 2/2/2015

5条回答
  •  伪装坚强ぢ
    2020-12-21 01:52

    If you want the simplest way just concat all of the separate parts

    var output = dt.getMonth( ) + 1 +'/'+ dt.getDate( ) + '/' +dt.getFullYear( );
    

    There are a few libraries that will handle more advanced stuff if you need it, but that is the lightest way I can think of doing what you are asking.

提交回复
热议问题