代码之家  ›  专栏  ›  技术社区  ›  user2024080

如何将日期格式转换为'2019-04-24T04:27:14.867Z`

  •  3
  • user2024080  · 技术社区  · 7 年前

    2019-04-24T04:27:14.867Z
    

    我试过这样做:

    var d = new Date();
    console.log(d);
    
    var utcDate1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
    
    console.log(utcDate1);
    
    var newFormat = new Date('04/21/19');
    
    console.log(newFormat);
    

    Live Demo .

    3 回复  |  直到 7 年前
        1
  •  3
  •   ellipsis    7 年前

    你可以用 .toISOString() 方法来获取该格式。 Refer

    var newFormat = new Date('04/21/2019');
    console.log(newFormat.toISOString());
        2
  •  2
  •   Kaushik    7 年前

    toISOString() Reference

    toISOString() 方法以简化的扩展ISO格式返回字符串

    var d = new Date();
    console.log(d);
    
    var utcDate1 = new Date();
    
    console.log(utcDate1.toISOString());
        3
  •  2
  •   Jack Bashford    7 年前

    toISOString 方法:

    var newFormat = new Date('04/21/19').toISOString();
    
    console.log(newFormat);