4 ms·
"Date hand-ported (h/t ksmith@netscape.com) from java.util.Date" I knew it!! The Date class is/was the worst thing about the Java library. It has confused a g
by BurningFrog 12y ago
"Date hand-ported (h/t ksmith@netscape.com) from java.util.Date"
I knew it!!
The Date class is/was the worst thing about the Java library. It has confused a generation of programmers about dates and time zones.
The main problem is that it's not a date, it's a time stamp.
- TazeTSchnitzel 12y agoMath was mostly copied from Java too.
- deleted 12y ago[deleted]
- TazeTSchnitzel 12y ago> In Java you legitimately have alternatives, since the alternatives can make the same raw OS calls that the java.util.Date library does. Not so in JS. So instead we HAVE to work with Date and work around its many warts. Uh, what? Yes, JavaScript's Date is the only way to get at that browser/OS stuff. So an alternative will use Date underneath to obtain that information. That doesn't mean the end-user has to work with Date.
- tracker1 12y agoI'll add that timezone information shifts politically over time... It'll never be consistent... your best bet is to ship all dates in UTC as much as possible (which `.toJSON` does) and display in local (which `new Date(jsonstr)` does). Dates are evil, even in C# with offsets it's not easy... and that's probably the best implementation of dates, with consistent updates I've seen.
- TazeTSchnitzel 12y ago> your best bet is to ship all dates in UTC as much as possible (which `.toJSON` does) and display in local (which `new Date(jsonstr)` does). Goodness yes, I really wish more sites did this. If you're asking a user what their timezone is, you're usually doing it wrong. Send UTC to the client, gracefully upgrade with JS to local time. This also solves those pesky DD/MM/YY vs MM/DD/YY issues!
- UnoriginalGuy 12y agoAnd while there are libraries which wrap Date in JS, there is no replacement that I've seen anyone propose. Why is a replacement needed you ask? Because Date still has exclusive access to a lot of underlying browser/OS DateTime information which isn't accessible any other way. In Java you legitimately have alternatives, since the alternatives can make the same raw OS calls that the java.util.Date library does. Not so in JS. So instead we HAVE to work with Date and work around its many warts. I've used quite a few DateTime libraries extensively, I'm yet to see someone "better" the DateTime .Net class. It "just works" and has few to no "gotchas."
- serve_yay 12y agoI don't think anyone would say JS's date situation is better than .NET's. .NET's is excellent, I agree. I wish we had something like that. You can't even reliably get the current locale in JS, it's insane.
- tosh 12y agoFor examples how a neat DateTime API can look like you might want to check out Dart's DateTime from the standard library: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:core.DateTime https://api.dartlang.org/apidocs/channels/stable/dartdoc-vie... or how Java 8 finally fixed DateTime inspired by Joda Time (http://www.joda.org/joda-time/ http://www.joda.org/joda-time/): http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html http://www.oracle.com/technetwork/articles/java/jf14-date-ti...
- BurningFrog 12y agoYeah, when Joda arrived, my Java programming life quality really improved.