I need to turn a Date object into a calendar in Java, and try to access its field value for HOUR_OF_DAY. Does anybody know how to do it?
4 Answers
Can I suggest using the Joda library if you're doing anything more than the most basic date/time work ?
DateTime dt = new DateTime();
int hour = dt.getHourOfDay();
I realise it's not quite what you're after, but the Joda date/time library offers the benefits of a much nicer and intuitive API, and avoids the non-intuitive gotchas of non-thread-safe date/time formatters It's well worth checking out.
1 Comment
João Silva
Yes, and it will still be the date/time library in the near future, as it doesn't look like JSR-310 (jsr-310.dev.java.net) is going to be ready for Java 7.