Lately I was playing with JS and I found something interesting. That is what I wrote into chrome console:
today = new Date()
-> Mon Apr 29 2013 13:06:01 GMT+0200 (CEST)
DAY = 1000 * 3600 * 24
-> 86400000
today - 2 * DAY
-> 1367060761452
today + 2 * DAY
-> "Mon Apr 29 2013 13:06:01 GMT+0200 (CEST)172800000"
And I am wondering why am I getting different types of answer depending on the type of operation - adding / subtracting. When I do something like that:
today - (-2) * DAY
everything is fine. Is there any ideology, or is it a bug?
today + 2 * DAY uses concatenation of strings. If you want do it properly, use today.getTime().
Example:
tomorrow = new Date()
tomorrow.setTime(today.getTime() + DAY)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With