Convert Returned String (YYYYMMDD) to Date

前端 未结 2 1803
自闭症患者
自闭症患者 2021-01-01 10:34

I have a string that contains 8 digits that represent a date. For example:

20120515

I\'d like to compare it with today\'s date, created in

2条回答
  •  借酒劲吻你
    2021-01-01 11:19

    If you want a small date library you can use moment.js.

    var a = moment("20120515", "YYYYMMDD");
    // then use any of moment's manipulation or display functionality
    a.format("MMM Do YYYY"); // May 15th 2012
    a.fromNow(); // 14 hours ago
    a.calendar(); // Today at 12:00 AM
    

提交回复
热议问题