开发者

Days with 25 hours on Java (Daylight saving days)

开发者 https://www.devze.com 2023-01-26 17:51 出处:网络
I have to prepare some app that will graph the use of resourc开发者_运维技巧es over time, but there is one day on the year that has 25 hours (the day with 23 hours is not a big problem).

I have to prepare some app that will graph the use of resourc开发者_运维技巧es over time, but there is one day on the year that has 25 hours (the day with 23 hours is not a big problem).

How can I represent that with a Date? What would be the best way of doing it?

I would like to use Date class, (as it works, is Comparable and so on) as a key, but I'm not sure if this would work... Any ideas?


The Date class itself simply represents an instant in time, from the UTC Unix epoch. It has no concept of time zones, calendars etc.

It's hard to know what exactly you're trying to represent, but in general Joda Time is a much better date/time API than the types in java.util.*.

My main advice on thinking about time-related issues is to be really, really clear about what concept each value is meant to be representing. If you're interested in a local date (a date within a particular calendar, with no reference to a particular time zone), then Joda Time's LocalDate class is probably what you're after. If you need to associate time zone information, then DateTime is probably your best bet - although that does represent an instant within a particular calendar and time zone, rather than a whole day.


It important not to confuse how time is represented and how it is displayed.

In its representation, you have only the number of milli-seconds since 1/1/1970. When you do calculations on this you are just comparing this long value.

When you display this time/date, depending on your timezone, you can have a period of 25 hours or 23 hours with the same day.

0

精彩评论

暂无评论...
验证码 换一张
取 消