Format JavaScript date as yyyy-mm-dd

后端 未结 30 2707
再見小時候
再見小時候 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

    A combination of some of the answers:

    var d = new Date(date);
    date = [
      d.getFullYear(),
      ('0' + (d.getMonth() + 1)).slice(-2),
      ('0' + d.getDate()).slice(-2)
    ].join('-');
    

提交回复
热议问题