简体   繁体   English

Moment js:moment(date:string,format:string)与moment(date:string).format(format:string)有什么区别?

[英]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')时刻('2021-12-12','YYYY-MM-DD')

to this one:对此:

moment('2021-12-12).format('YYYY-MM-DD)时刻('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.但是,当您将期望格式作为第二个参数传递给 moment 方法时,您实际上并没有转换数据类型。 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有关更多信息,您可以阅读内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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