Re: java.sql.Date returning wrong date
"Eric Sosman" <Eric.Sosman@sun.com> wrote in message
news:1175270254.565324@news1nwk...
Steve Austin wrote On 03/30/07 11:28,:
public class Testing {
public static void main(String[] args) {
try {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-
dd");
Bzzzt! What do you imagine "mm" means to SimpleDateFormat?
To put it another way, what do you suppose you'd see if you also
displayed the time of day from the converted Date?
(Despite the identity of my employer, I cannot think of any
good reason for this bizarre behavior. It has at one time or
another tripped up everybody and his Uncle Charlie, and will keep
doing so for the forseeable future. That's "lost productivity,"
exactly the sort of thing Java was supposed to reduce. Could we
have had an easily-remembered mnemonic device like "Capital letters
for the big time units, lower-case for the small?" No, that would
make too much sense. Can *anyone* suggest a way to remember the
date format string codes short of tattooing them to the inside of
one's eyelids?)
How about a checkstyle/findbugs/lint/whatever plugin/module/whatever
that flags any occurrence of passing "yyyy-mm-dd" to SimpleDataFormat(),
as it's very rare to want to include minutes between years and days. More
generally, any sequence of 'm' between 'y' and 'd' with no other
alphabetic characters (e.g. ' ', '-' and '/' are not alphabetic
characters, and so don't count) in between is a danger sign.
- Oliver