Is there any way to represent a Date (without a time) that is associated with a time zone? The only representation of date without time I was able to find is LocalDate which I guess doesn't allow you to specify a zone.
2 Answers
Short answer, there is no such type in Java-8.
The combination of a calendar date and a time zone is questionable, at least to say. Reason is that time zones are intended to operate on date AND time. Since time zones are responsible for translating between global instants/moments and local timestamps (including date AND time) a combination of just a date and a zone is simply not complete to enable such transformations.
The only similar type I am aware of is the type
xs:date
in XML-Schema which explicitly allows an extra offset (which is less than a time zone because it does not store daylight saving rules or historical offsets). In my opinion the W3C-consortium has rather introduced this type for symmetry reasons not for real time-tasks. JSR-310 (which introduced the java.time-package into Java-8) originally intended to offer a similar type called OffsetDate
, see also this page. It was removed however when Java-8 was finished for release.
Of course, you can write a simple class yourself which holds two state members of types LocalDate
and ZoneId
(but what is your use-case???). For XML, I would rather choose LocalDate
and ZonalOffset
.

- 42,708
- 7
- 104
- 126
-
1Java time author Stephen Colebourne briefly discusses the absence of a `ZonedDate` in [this answer](https://stackoverflow.com/a/7841875/1108305). – M. Justin Mar 09 '21 at 21:20
Maybe you can use the class ZonedDateTime:
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("Europe/Paris"));
LocalDate localDate = zonedDateTime.toLocalDate(); // gets you the date without time
ZoneId zoneId = zonedDateTime.getZone(); // gets you the timezone

- 183
- 1
- 1
- 5