Questions tagged [zoneddatetime]

`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.”

339 questions
14
votes
2 answers

Extracting date, hour and minute from Instant.now() generated date

I have this code that generates a date and time, ZoneId z = ZoneId.of( "Africa/Nairobi" ); Instant instant = Instant.now(); ZonedDateTime zdt = instant.atZone(z); return zdt.toString(); //2018-03-19T09:03:22.858+03:00[Africa/Nairobi] Is…
Gandalf
  • 1
  • 29
  • 94
  • 165
13
votes
2 answers

Java8- ZonedDateTime with DateTimeFormatter not recognizing the format

I am using the ZonedDateTime with DateTimeFormatter of Java 8. When I try to parse my own pattern it doesn't recognizes and throws an exception. String oraceDt = "1970-01-01 00:00:00.0"; DateTimeFormatter formatter =…
Venkat
  • 147
  • 1
  • 1
  • 10
12
votes
3 answers

@CreatedBy and @LastModifiedDate are no longer working with ZonedDateTime?

i have updated an old spring boot 1.5.3 project to spring boot 2.0.0. RELEASE. I have an auditing entity with two fields of type ZonedDateTime annotated with @CreatedBy and @LastModifiedDate. In the previous versions everything was working fine.…
12
votes
2 answers

How to convert any Date time to UTC using ZonedDateTime or Java 8

I am trying to convert date 06-12-2015 02:10:10 PM from default zone to UTC using ZonedDateTime. LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); ZonedDateTime utc = ZonedDateTime.of(localDateTime,…
Bilal Shah
  • 1,135
  • 7
  • 17
  • 42
11
votes
2 answers

LocalTime() difference between two times

I have a flight itinerary program where I need to get difference between departure and arrival time. I get these specified times as String from the data. Here is my problem: import static java.time.temporal.ChronoUnit.MINUTES; import…
Naeem Khan
  • 950
  • 4
  • 13
  • 34
11
votes
2 answers

ZonedDateTimeDeserializer is missing in jackson jsr310

I'm parsing a ZonedDateTime using like this: @JsonSerialize(using = ZonedDateTimeSerializer.class) private ZonedDateTime expirationDateTime; I need to be able to properly deserialize this date. However, there is no deserializer for this that is…
dvelopp
  • 4,095
  • 3
  • 31
  • 57
10
votes
2 answers

How to map a TIMESTAMP column to a ZonedDateTime JPA entity property?

I'm using Spring data jpa and mariadb latest version, and MariaDB 10.3.16 +--- org.springframework.boot:spring-boot-starter-data-jpa -> 2.1.5.RELEASE ... | +--- org.springframework.boot:spring-boot-starter-jdbc:2.1.5.RELEASE ... | +---…
chaeyk
  • 491
  • 1
  • 8
  • 20
10
votes
5 answers

ZonedDateTime to Date before Java 8 in early Android

I am trying to replace the ZonedDateTime.toInstant method because it is only available since API 26 for Android. But my app is supposed to support API 19. I want to convert the ZonedDateTime to a Date so i can do something like this: final Calendar…
manuelwaldner
  • 551
  • 1
  • 5
  • 24
10
votes
6 answers

Java 8 Time API - ZonedDateTime - specify default ZoneId when parsing

I am trying to write a generic method to return a ZonedDateTime given a date as String and its format. How do we make ZonedDateTime to use the default ZoneId if it is not specified in the date String? It can be done with java.util.Calendar, but I…
RuntimeException
  • 1,593
  • 2
  • 22
  • 31
9
votes
1 answer

Why do ZonedDateTime and Calendar disagree on the hour in year 2050?

Consider the following code: ZoneId zoneId = ZoneId.of("America/Los_Angeles"); long currMillis = 2530778400000L; Instant curr = Instant.ofEpochMilli(currMillis); LocalDateTime dt = LocalDateTime.ofInstant(curr, zoneId); //the local one just for…
Alexander
  • 2,761
  • 1
  • 28
  • 33
9
votes
2 answers

What Java DateTime class should I use?

We have a library used for generating reports. It reads from a data file (SQL, XML, JSON, etc.), the datetime may then be modified in a user written equation, and then it is formatted as specified for the report output. The use in an equation can be…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
9
votes
2 answers

The request sent by the client was syntactically incorrect Java ZonedDateTime backend

I am hoping to get some help debugging this problem. If I send the following JSON to my backend it works correctly: { "approvalRequired": false, "location": { "locationName": "<+37.33233141,-122.03121860> +\/- 5.00m (speed 0.00 mps…
AlexK
  • 336
  • 8
  • 21
  • 41
9
votes
1 answer

Java: ZonedDateTime - parse timestring without timezone

I have a datetime-string WITHOUT a specified timezone. But I want to parse it with ZonedDateTime to give it a timezone-meaning in the act of parsing. This code is working but uses LocalDateTime for parsing - and then convert it to ZonedDateTime with…
chris01
  • 10,921
  • 9
  • 54
  • 93
8
votes
2 answers

Convert ZonedDateTime to end of the day

In this code, Instant i = Instant.ofEpochMilli(inputDate); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instance, ZoneId.of(marketplaceIdToZoneMap.get(timeZone))); I just want this time zoneDateTime to be end of the day, like if value of…
Amit Kumar
  • 377
  • 4
  • 17
8
votes
2 answers

How to get the maximum of two ZonedDateTime instances?

I have two ZonedDateTime instances: final ZonedDateTime a = ...; final ZonedDateTime b = ...; I want to get the maximum of those two values. I want to avoid having to write custom ad-hoc code. What is the best way to do this in Java 8? I am…
1
2
3
22 23