tags:

views:

87

answers:

1

What time is the start of a day, say 01/01/2010?

Is it 00:00:00:000 ? or is that midnight?

[edit]

It might be a stupid question but I'm confused because I used Calendar.set(Calendar.HOUR, 0) but this gives me a time of 12:00:00.

and now I've realised I should be using HOUR_OF_DAY

+6  A: 

The start of the day isn't always midnight. It can depend on the time zone and date. (If the clock moves forward an hour at the start of the day, it will start at 1am.)

That's why Joda Time has things like LocalDate.toDateTimeAtStartOfDay - and they're well worth using.

But yes, normally it's at 00:00:00 which is midnight. (This can also be formatted as "12am" depending on your locale etc.)

Jon Skeet
Really? I had no idea there was a time zone dependence. Thanks for the heads up, Jon. I'm going to remove my (incorrect) answer.
duffymo
+1 for timezone dependency.
Thorbjørn Ravn Andersen
I wouldn't know either, if it hadn't bitten me before. I don't know how many time zones do "spring forward" at midnight - I believe there's one in South America that does though.
Jon Skeet
I don't think any current DST rules have a transition from midnight to 1AM, but many historical rules had. Using the Java calendar to set such a date to midnight causes the calendar to fallback to the first existing time on that actual date, just as Joda's toDateTimeAtStartOfDay.
jarnbjo
@jarnbjo: If there have been changes on that front they must have been pretty recent - I'm pretty sure I had an exception due to this case just last year. Will have a look some time.
Jon Skeet