Questions tagged [localdatetime]

204 questions
32
votes
6 answers

How to convert LocalDateTime to OffsetDateTime?

How to convert LocalDateTime to OffsetDateTime? private OffsetDateTime getEntryDate(Payment payment) { return Optional.ofNullable(payment) .map(Payment::getEntryDate) .map(SHOULD RETURN OffsetDateTime) …
Melad Basilius
  • 3,847
  • 10
  • 44
  • 81
25
votes
5 answers

How to use the Java 8 LocalDateTime with JPA and Hibernate

I have the following class description snippet: ... @Column(name = "invalidate_token_date") @Temporal(TemporalType.TIMESTAMP) private LocalDateTime invalidateTokenDate; .... This code doesn't work on Hibernate 4 because @Temporal doesn't…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
21
votes
9 answers

What does this error mean? java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.time.LocalDate.year

I'm trying to make a method, which uses the Json data with jackson library to have a list of objects. If I run my code, I get the error: java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.time.LocalDate.year…
user17173618
11
votes
1 answer

LocalDateTime to milliseconds difference in Java 8 and Java 11

I'm currently in the process of upgrading a few projects from Java 8 to Java 11 where one of the unit tests for a converter failed. Basically the problem stems from the equality check failing due to a a date precision which previously passed with…
geneqew
  • 2,401
  • 5
  • 33
  • 48
10
votes
3 answers

How to parse an ISO date with LocalDateTime.parse(...)

I want to parse a date string like 2011-11-30 like this: LocalDateTime.parse("2011-11-30", DateTimeFormatter.ISO_LOCAL_DATE) But I get the following exception: java.time.format.DateTimeParseException: Text '2011-11-30' could not be parsed: Unable…
deamon
  • 89,107
  • 111
  • 320
  • 448
7
votes
1 answer

How can you format a kotlinx-datetime LocalDateTime?

I'm converting some code from using Java 8's LocalDatetime to using the version from kotlinx-datetime and I can't find any formatting methods. Specifically, I'm replacing a FormatStyle.MEDIUM. Do they not exist and I need to write the…
Sean
  • 2,632
  • 2
  • 27
  • 35
6
votes
2 answers

How to round it down to the closest 5 minute interval if it is 1,2,3,4 minutes ahead?

I want to round down an Instant / LocalDateTime to its closest 5 minutes interval in Java. Examples: Suppose the time is: 2021-02-08T19:01:49.594 or 2021-02-08T19:02:49.594 or 2021-02-08T19:03:49.594 or 2021-02-08T19:04:49.594 Expected…
Dev
  • 794
  • 1
  • 9
  • 21
5
votes
2 answers

Creating a list of avalible Timeslots based on a list LocalDateTime objects and a List of taken Timeslots with Streams

I have a List that contains entity Timeslot with the following fields: timeslot_id; day; start_time; end_time. For example, this list contains two records: start_time of the first record equals 9:00 and end_time equals…
Dmytro Klopov
  • 121
  • 2
  • 9
5
votes
1 answer

Convert swagger format: date-time to LocalDateTime.class

I have a swagger.json specification that I can not change. I'm using swagger-codegen to create a library from my swagger.json like this: $ java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -o . The problem is that in my…
5
votes
2 answers

LocalDateTime format with time zone and milliseconds

I'm trying to write a DateTimeFormatter to parse the following format: 2020-05-29T07:51:33.106-07:00 I have looked at ISO_OFFSET_DATE_TIME, but the problem is it does not contain milliseconds. So I decided to write on my own. It is easy to do so…
Some Name
  • 8,555
  • 5
  • 27
  • 77
4
votes
2 answers

Converting LocalDateTime to Instant give different values

I am trying to use LocalDateTime to manipulate dates in my application but I have noticed that getting epoch seconds from it returns different values from what I expected val now1 = Instant.now().epochSecond - 60 val now2 =…
Emmanuel Mtali
  • 4,383
  • 3
  • 27
  • 53
4
votes
4 answers

Kotlin date parsing is not working properly

So I have been looking up on how to properly parse an incoming datetime, problem is that this string contains the zone as well which apparently can't be parsed for some reason. To give an example of the incoming date time…
4
votes
4 answers

Date Format Issue With DateTimeFormatter

I have a date in the following format: 1/1/2020 3:4:7 AM I am trying to format it using DateTimeFormatter. I have the following code with a formatter to parse it, but it doesn't work. LocalDateTime date = LocalDateTime.parse("1/1/2020 3:4:7 AM",…
user2254180
  • 844
  • 13
  • 30
3
votes
4 answers

Why does LocalDateTime.ofInstant() requires ZoneId

In Java, If Instant represents a point in time, encoded as date and time in UTC. And LocalDateTime represents a point in time, encoded as date and time in the JVM local timezone. Why then does LocalDateTime.ofInstant() require a ZoneId as a second…
Mike
  • 53
  • 1
  • 5
3
votes
3 answers

Get the month last date

I have a LocalDateTime object I want to get the last date of the month. So if the localDateTime points to today's date of 29th October. I want to convert it to 31st October Is there a clean and easy way to do it? My Thoughts: One way would be to…
joseph
  • 147
  • 7
1
2 3
13 14