3 ms·
java.util.Date wasn't broken per se, since people have been using it since Java first came out. It's just not pleasant to work with, the naming conventions are
by bluedevil2k 13y ago
java.util.Date wasn't broken per se, since people have been using it since Java first came out. It's just not pleasant to work with, the naming conventions are wrong, it's short-sighted in terms of international dates, etc. Classic example of what's wrong with the old methods - the dates are 0-indexed.
- yonran 13y agoThe months and days of week are 0-indexed. The dates of month are 1-indexed. Same as javascriopt. You always have to be careful with this API, but it helps to remember that they return an index in an array for the items that have a name in English (“January” and “Sunday”).
- mbell 13y agoHere is one example of why I think Date is broken: For quite awhile (maybe still?) calling `new Date()` made a synchronized call to a static method to try and figure out the default timezone. That created nasty lock contention in multithreaded code, nuking performance. Of course there is no way to create a new Date with a particular time zone. The other option was using the Calendar class since you could pass in a time zone, but a Calendar takes ~20 times more memory and is slow as hell to create. This meant you couldn't do something as simple as creating new Date classes with reasonable performance.