Format JavaScript date as yyyy-mm-dd

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

    Shortest

    .toJSON().slice(0,10);
    

    var d = new Date('Sun May 11,2014' +' UTC');   // Parse as UTC
    let str = d.toJSON().slice(0,10);              // Show as UTC
    
    console.log(str);

提交回复
热议问题