how to display a date as 2/25/2007 format in javascript, if i have date object

后端 未结 6 1183
攒了一身酷
攒了一身酷 2020-12-21 04:28

how to display a date as 2/25/2007 format in javascript, if i have date object

6条回答
  •  -上瘾入骨i
    2020-12-21 04:52

    Your best option for all users (internationally) is toLocaleDateString.

    var date = new Date("2007-02-25 01:00:00"); // for some reason a time is needed
    var dateString = date.toLocaleDateString();
    console.log(dateString); // outputs 2/25/2007
    

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

提交回复
热议问题