简体   繁体   中英

javascript: convert string to ISO-compatible date

I have a list of dates like so

august 2015
september 2015
october 2015
november 2015
december 2015

that I want to convert to ISO format for storage

2015-08-01T00:00:00-07:00
2015-09-01T00:00:00-07:00
2015-10-01T00:00:00-07:00
2015-11-01T00:00:00-07:00
2015-12-01T00:00:00-08:00

Typically, I use moment.js for something like this, but it looks like they are soon going to stop supporting this functionality .

How do I write something that replaces it? Thus far, I've been using moment because I didn't want to have to worry about things like Daylight Savings adjustments, etc.

Looks like moment does handle this, fairly trivially; you just need to add a format for parsing :

monthMoment = moment("august 2015", "MMMM YYYY");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM