`ZonedDateTime` is a standard Java class representing a “date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00 Europe/Paris.”
Questions tagged [zoneddatetime]
339 questions
150
votes
9 answers
How to convert ZonedDateTime to Date?
I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver for Java understands only the Date type.
So assuming that in my code I am…

Milen Kovachev
- 5,111
- 6
- 41
- 58
129
votes
10 answers
Is there any way to convert ZoneId to ZoneOffset in Java 8?
I have an epoch second and a zoneId (see method1 below).
It can be convert to LocalDateTime with system default zoneId, but I don't find the way to convert epoch second to LocalDateTime (see method2 below), because there is no…

Renkai
- 1,991
- 2
- 13
- 18
86
votes
2 answers
Java 8: How to create a ZonedDateTime from an Epoch value?
Java 8's LocalDateTime has an ofEpochSecond method. Unfortunately, there is no such method in the ZonedDateTime. Now, I have an Epoch value and an explicit ZoneId given. How do I get a ZonedDateTime out of these?

rabejens
- 7,594
- 11
- 56
- 104
64
votes
3 answers
How to format a ZonedDateTime to a String?
I want to convert a ZonedDateTime to a String in the format of ("dd/MM/yyyy - hh:mm"). I know this is possible in Joda-Time other types, just using their toString("dd/MM/yyyy - hh:mm")....But this doesn't work with ZonedDateTime.toString().
How can…

Michel Feinstein
- 13,416
- 16
- 91
- 173
57
votes
5 answers
Converting string to 'Instant'
I am trying to convert datetime in a string to an Instant instance using Java 8 or a utilities package.
For example,
String requestTime = "04:30 PM, Sat 5/12/2018";
to
Instant reqInstant should result in 2018-05-12T20:30:00.000Z
reqString is in…

masterfly
- 861
- 4
- 11
- 24
54
votes
5 answers
Convert ZonedDateTime to LocalDateTime at time zone
I have an object of ZonedDateTime that is constructed like this
ZonedDateTime z = ZonedDateTime.of(LocalDate.now().atTime(11, 30), ZoneOffset.UTC);
How can I convert it to LocalDateTime at time zone of Switzerland? Expected result should be 16…

Vitalii
- 10,091
- 18
- 83
- 151
47
votes
5 answers
Jackson serializes a ZonedDateTime wrongly in Spring Boot
I have a simple application with Spring Boot and Jetty. I have a simple controller returning an object which has a Java 8 ZonedDateTime:
public class Device {
// ...
private ZonedDateTime lastUpdated;
public Device(String id, ZonedDateTime…

jbx
- 21,365
- 18
- 90
- 144
32
votes
2 answers
How to convert ZonedDateTime to milliSecond in Java?
I'm trying to convert ZonedDateTime to milliseconds using below code.
LocalDateTime ldt = LocalDateTime.now();
ZonedDateTime zonedDateTime =ldt.atZone(ZoneId.of(""Asia/Kolkata""));
zonedDateTime.toInstant().toEpochMilli();
But this one returns…

Arun
- 510
- 2
- 5
- 9
27
votes
4 answers
ZonedDateTime toString compatability with ISO 8601
I am trying to ensure that calling toString() on my ZonedDateTime Object will comply with ISO-8601 format.
The documentation for the toString() method states:
...The output is compatible with ISO-8601 if the offset and ID are the
same
Does this…

theyuv
- 1,556
- 4
- 26
- 55
26
votes
3 answers
Convert java.sql.Timestamp to Java 8 ZonedDateTime?
Migrating Joda time to Java 8
Joda:
UserObject user = new UserObject()
user.setCreatedAt(new DateTime(rs.getTimestamp("columnName")));`
Migrating to Java 8
This is my code; it does compile; I am doubtful if it…

Parameswar
- 1,951
- 9
- 34
- 57
26
votes
1 answer
Set the time-of-day on a ZonedDateTime in java.time?
How can I alter the time-of-day portion of an existing ZonedDateTime object? I want to keep the date and time zone but alter the hour and minutes.

Basil Bourque
- 303,325
- 100
- 852
- 1,154
23
votes
5 answers
ZonedDateTime to UTC with offset applied?
I am using Java 8
This is what my ZonedDateTime looks like
2013-07-10T02:52:49+12:00
I get this value as
z1.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
where z1 is a ZonedDateTime.
I wanted to convert this value as 2013-07-10T14:52:49
How…

daydreamer
- 87,243
- 191
- 450
- 722
20
votes
1 answer
Instant vs ZonedDateTime
I just do not quite understand which one of those two I should use for the following example:
We have an OfferEntity which has a member availableDay which is the date at which the offer is available.
Now, the table will look something like…

Stefan Falk
- 23,898
- 50
- 191
- 378
20
votes
3 answers
ZonedDateTime comparison: expected: [Etc/UTC] but was: [UTC]
I was comparing two dates which seem to be equal, but they contain a different name of zones: one is Etc/UTC, another is UTC.
According to this question: Is there a difference between the UTC and Etc/UTC time zones? - this two zones are the same.…

Andremoniy
- 34,031
- 20
- 135
- 241
19
votes
3 answers
Set hours minutes and seconds to 00 in ZonedDateTime or Instant
I have a date string in Utc format -
String dateStr = "2017-03-03T13:14:28.666Z";
And I want to convert it to below format in Java date representation in ZonedDateTime.
When ZonedDateTime is printed it should show
String dateStr =…

WitVault
- 23,445
- 19
- 103
- 133