4 ms·
True, it's been so long since I Java'd at all, that I simply don't remember the idiomatic ways to do things. And those ways have probably changed quite a bit in
by bane 13y ago
True, it's been so long since I Java'd at all, that I simply don't remember the idiomatic ways to do things. And those ways have probably changed quite a bit in the intervening years.
Still it seems conceptually weird that the idea of a DateFormat object can be a thing, when it's just a String with the magic Format language.
Parsing or formatting (the verbs) seem more like actions to be taken on a Date itself. It seems much tidyier to me to just keep all that contextually in the Date class.
- kbolino 13y agoFrom a theoretical perspective, date formatting is a behavior that can be accomplished in a number of different ways. While the pre-Java 8 API only provides SimpleDateFormat, JodaTime provides a similar class and a slew of formatters based upon ISO8601 that don't use patterns at all. From a practical standpoint, SimpleDateFormat and its analogues don't operate directly on the format string you supply, but instead compile it into a form that is easier to process. If Date.format was the only way to format a date, then the format pattern would have to be recompiled on every call (or else cached, which would affect thread safety). Now, String.split exists, despite having to recompile the regular expression every time it is called (except for certain optimized cases), so presumably Date.format could also exist, but DateFormat would still be preferable for many cases.