Javascript equivalent of php's strtotime()?

后端 未结 8 1236
無奈伤痛
無奈伤痛 2020-11-27 19:33

In PHP, you can easily convert an English textual datetime description into a proper date with strtotime().

Is there anything similar in Javascript?

8条回答
  •  [愿得一人]
    2020-11-27 20:01

    I jealous the strtotime() in php, but I do mine in javascript using moment. Not as sweet as that from php, but does the trick neatly too.

    // first day of the month
    var firstDayThisMonth = moment(firstDayThisMonth).startOf('month').toDate();
    

    Go back and forth using the subtract() and add() with the endOf() and startOf():

    // last day of previous month
    var yesterMonthLastDay = moment(yesterMonthLastDay).subtract(1,'months').endOf('month').toDate();
    

提交回复
热议问题