我的代码中需要一个new Date()
,并且绝对不关心它将创建哪个日期/时间,因为我将在之后设置日期和时间。我只需要一个新对象。怎么做?因为new Date()
会检查实际时间。我可以创建一些默认日期吗?
最佳答案
尝试这个变体:
新日期(0)
来自此来源: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date
JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.
If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.
这意味着 0
参数确实可以提高性能。
关于javascript - 最快创建新日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44005543/