Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  63] [ 1]  / answers: 1 / hits: 26966  / 12 Years ago, tue, march 6, 2012, 12:00:00

new Date() takes an ordinal and returns a Date object.

What does Date() do, and how come it gives a different time?



>>> new Date(1329429600000)
Date {Fri Feb 17 2012 00:00:00 GMT+0200 (القدس Standard Time)}
>>> Date(1329429600000)
Tue Mar 06 2012 15:29:58 GMT+0200 (Jerusalem Standard Time)

More From » javascript

 Answers
60

From the specs:




When Date is called as a function rather than as a constructor, it returns a String representing the current time (UTC).




and:




When Date is called as part of a new expression, it is a constructor: it initialises the newly created object.




So, new Date(...) returns an object such that obj instanceof Date is true, whereas Date(...) basically returns the same as new Date().toString().


[#87033] Sunday, March 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;