Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "new Date().valueOf()" and Date().valueOf()"

Tags:

javascript

Why are the two expressions below returning different results?

Date().valueOf()
"Fri Feb 07 2014 16:03:34 GMT-0500 (Eastern Standard Time)"

new Date().valueOf()
1391807020802

Date().toString()
"Fri Feb 07 2014 16:09:21 GMT-0500 (Eastern Standard Time)"

new Date().toString()
"Fri Feb 07 2014 16:09:26 GMT-0500 (Eastern Standard Time)"
like image 318
ROTOGG Avatar asked Nov 22 '25 18:11

ROTOGG


1 Answers

Date() returns a timestamp formatted as a string.

new Date() returns a Date instance.

Instances of the Date constructor have values that convert to numbers, which is why new Date().valueOf() returns a number. Strings are simply strings, so when you call Date().valueOf() you get the same string result.

like image 154
zzzzBov Avatar answered Nov 24 '25 06:11

zzzzBov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!