MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/btxz72/what_are_some_javascript_things_beginners_dont/ep53cma
r/javascript • u/[deleted] • May 28 '19
383 comments sorted by
View all comments
Show parent comments
34
This is true, but that's something even beginners (hopefully) should know.
The date thing is weird because months start at zero, but days, hours, seconds, and milliseconds start at 1.
new Date(2019, 1, 1, 1, 1, 1) gives you Fri Feb 01 2019 01:01:01
new Date(2019, 1, 1, 1, 1, 1)
0 u/[deleted] May 28 '19 [deleted] 12 u/throwAwayDev_ May 28 '19 I think it's fair to be angry, but unreasonable to blame JS. Useful thread 3 u/MuskasBackpack May 28 '19 I think pretty much every language has things like this. 1 u/TheCarnalStatist May 28 '19 JavaScript has more than most. I get why due to it's history but man is it frustrating some days. 2 u/fucking_passwords May 28 '19 related: doing math with floats 3 u/the_php_coder May 28 '19 Not in the latest version of node LTS apparently. I just tried and I got jan instead of feb:> new Date(2019, 1, 1, 1, 1, 1); 2019-01-31T19:31:01.000Z 3 u/yitianjian May 28 '19 Did you get January 31? 2 u/the_php_coder May 28 '19 Oh yeah and that too in UTC timezone, not my local one. Turns out this weird behavior is built into nodejs. Almost every other lang I've worked on gives local time by default, looks like I've got a lot to learn! 2 u/onbehalfofthatdude May 28 '19 Local server time wouldn't be that useful 1 u/PriorProfile May 28 '19 This actually makes sense in a way.Hours, minutes, seconds don’t start at 01:01:01. They start at 00:00:00.Think of it this way: your example gives you the second millisecond of the second minute of the second hour of the first day of the second month.Days are actually the odd ones. Not the months. But it would make even less sense to refer to days as 0 index I think.
0
[deleted]
12 u/throwAwayDev_ May 28 '19 I think it's fair to be angry, but unreasonable to blame JS. Useful thread 3 u/MuskasBackpack May 28 '19 I think pretty much every language has things like this. 1 u/TheCarnalStatist May 28 '19 JavaScript has more than most. I get why due to it's history but man is it frustrating some days. 2 u/fucking_passwords May 28 '19 related: doing math with floats
12
I think it's fair to be angry, but unreasonable to blame JS. Useful thread
3 u/MuskasBackpack May 28 '19 I think pretty much every language has things like this. 1 u/TheCarnalStatist May 28 '19 JavaScript has more than most. I get why due to it's history but man is it frustrating some days. 2 u/fucking_passwords May 28 '19 related: doing math with floats
3
I think pretty much every language has things like this.
1 u/TheCarnalStatist May 28 '19 JavaScript has more than most. I get why due to it's history but man is it frustrating some days. 2 u/fucking_passwords May 28 '19 related: doing math with floats
1
JavaScript has more than most. I get why due to it's history but man is it frustrating some days.
2 u/fucking_passwords May 28 '19 related: doing math with floats
2
related: doing math with floats
Not in the latest version of node LTS apparently. I just tried and I got jan instead of feb:
> new Date(2019, 1, 1, 1, 1, 1); 2019-01-31T19:31:01.000Z
3 u/yitianjian May 28 '19 Did you get January 31? 2 u/the_php_coder May 28 '19 Oh yeah and that too in UTC timezone, not my local one. Turns out this weird behavior is built into nodejs. Almost every other lang I've worked on gives local time by default, looks like I've got a lot to learn! 2 u/onbehalfofthatdude May 28 '19 Local server time wouldn't be that useful
Did you get January 31?
2 u/the_php_coder May 28 '19 Oh yeah and that too in UTC timezone, not my local one. Turns out this weird behavior is built into nodejs. Almost every other lang I've worked on gives local time by default, looks like I've got a lot to learn! 2 u/onbehalfofthatdude May 28 '19 Local server time wouldn't be that useful
Oh yeah and that too in UTC timezone, not my local one. Turns out this weird behavior is built into nodejs. Almost every other lang I've worked on gives local time by default, looks like I've got a lot to learn!
2 u/onbehalfofthatdude May 28 '19 Local server time wouldn't be that useful
Local server time wouldn't be that useful
This actually makes sense in a way.
Hours, minutes, seconds don’t start at 01:01:01. They start at 00:00:00.
Think of it this way: your example gives you the second millisecond of the second minute of the second hour of the first day of the second month.
Days are actually the odd ones. Not the months. But it would make even less sense to refer to days as 0 index I think.
34
u/Careerier May 28 '19
This is true, but that's something even beginners (hopefully) should know.
The date thing is weird because months start at zero, but days, hours, seconds, and milliseconds start at 1.
new Date(2019, 1, 1, 1, 1, 1)gives you Fri Feb 01 2019 01:01:01