简体   繁体   中英

Moment js: What is the different between moment(date:string, format:string) to moment(date:string).format(format:string)?

I want to know what is the different between:

moment('2021-12-12', 'YYYY-MM-DD')

to this one:

moment('2021-12-12).format('YYYY-MM-DD)

when you use the format method in moment, you convert the date to the string with the desire format. But when you pass the desire format as the second argument to the moment method, you do not actually converting the data type. But you want that your date to be in a written format. this is a big difference between first option and second option that you wrote. For more info you can read this

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