简体   繁体   中英

date-fns convert string date format 'MMM-DD-YYYY' into Date

How can I convert using date-fns the following string into Date?

Jul-30-2021 (format MMM-DD-YYYY).

Using momentjs I can convert it using:

moment('Jul-30-2021', 'MMM-DD-YYYY')

this way :

 const setDateMDY = dteSTR => { let [m,d,y] = dteSTR.split('-') return new Date(`${m} ${d}, ${y} 00:00:00`) } let date1 = setDateMDY('Jul-30-2021') console.log( date1.toLocaleString() )

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