简体   繁体   English

在 moment.js 中避免今天

[英]Avoid today's day in moment.js

In my application, moment.js, gives the today's day if inside moment is an empty array:在我的应用程序 moment.js 中,如果内部 moment 是一个空数组,则给出今天的日期:

 const date = moment([]).format('MM/DD/YYYY'); console.log(date)
 <script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>

How to avoid this, and if inside is an empty array to get the array, but not today's day?如何避免这种情况,如果里面是一个空数组来获取数组,而不是今天呢?

https://momentjs.com/docs/#/parsing/array/ https://momentjs.com/docs/#/parsing/array/

If you pass an array as parameter of moment, it will read it like [year, month, day, hour, minute, second, millisecond].如果您将数组作为时刻的参数传递,它将读取为 [年、月、日、小时、分钟、秒、毫秒]。 If you pass an empty array it works like if you didn't send any parameters, so it works like moment() or new Date(), assigning actual date.如果您传递一个空数组,它的工作方式就像您没有发送任何参数一样,因此它的工作方式类似于 moment() 或 new Date(),分配实际日期。

If you don't want it to work in this way you can insert a null instead of an empty array and it will be an invalid date, not actual date.如果您不希望它以这种方式工作,您可以插入 null 而不是空数组,这将是无效日期,而不是实际日期。

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

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