Format JavaScript date as yyyy-mm-dd

后端 未结 30 2731
再見小時候
再見小時候 2020-11-22 01:28

I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript?

30条回答
  •  梦谈多话
    2020-11-22 02:07

    If you don't have anything against using libraries, you could just use the Moments.js library like so:

    var now = new Date();
    var dateString = moment(now).format('YYYY-MM-DD');
    
    var dateStringWithTime = moment(now).format('YYYY-MM-DD HH:mm:ss');

提交回复
热议问题