Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the use cases justifying the 310 OffsetDate type?

Tags:

java-8

jsr310

OffsetDate represents a date with a zone offset. I don't understand the purpose this class serves, what are the main use cases justifying its existence?

like image 842
Brian Harris Avatar asked Oct 17 '11 00:10

Brian Harris


People also ask

What is the difference between OffsetDateTime and ZonedDateTime?

Instant is the simplest, simply representing the instant. OffsetDateTime adds to the instant the offset from UTC/Greenwich, which allows the local date-time to be obtained. ZonedDateTime adds full time-zone rules. It is intended that ZonedDateTime or Instant is used to model data in simpler applications.

How do I get time from OffsetDateTime?

It obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30. It gets the range of valid values for the specified field. It converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. It returns a copy of this OffsetDateTime with the time truncated.

Which package contains date or time JSR 310 API in Java 8?

The project has been led jointly by the author of Joda-Time (Stephen Colebourne) and Oracle, under JSR 310, and will appear in the new Java SE 8 package java. time .


1 Answers

When analysing the basic components of dates and times there are four basic elements:

  • date
  • time
  • offset (hours plus/minus from Greenwich)
  • time-zone

These naturaly form seven classes:

  • LocalDate - date only
  • LocalTime - time only
  • LocalDateTime - date + time
  • OffsetDate - date + offset
  • OffsetTime - time + offset
  • OffsetDateTime - date + time + offset
  • ZonedDateTime - date + time + offset + zone

(a time-zone can only be used if you know the date and the time, so there is no ZonedDate or ZonedTime class)

The first six forms directly match XML schema definitions, which in effect justifies their existence. In application design terms I suspect that OffsetDate will be the least used of the seven classes.

Update: 2013-01-24: OffsetDate won't be in JDK 1.8.

like image 145
JodaStephen Avatar answered Sep 28 '22 06:09

JodaStephen