Skip to content
Advertisement

Tag: localdatetime

How to parse this date/time in Java/Kotlin?

I have this NMEA timestamp: 120722202122 and I want to parse it. I tried Playground but I get an Exception: I don’t know what the Exception wants to tell me or what my pattern should look like. Answer I assume you’ve probably meant the day of the month d, not the day of the year D. In your pattern, you’ve

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

I have a List<Timeslot> 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 10:00. start_time of second object equals 10:00 and end_time equals 11:00. And the second list contains timestamps List<LocalDateTime>: I need to create a third List<Timeslot> that will

Random time and date

I want to get a date that generates the time from now to 2685 days back and a random time. The format I accept must be “uuuu-MM-dd’T’HH: mm: ssZ”. Currently my program is generating a random date but I am not able to create a random time because Duration conflicts with Period Answer Something like this may be?

Java LocalDateTime remove the milliseconds from UTC timezone

I am trying to truncate milliseconds from a UTC time zone. I have the code below where I am able to remove milliseconds but I still get the Z at the end. This outputs the following: ====Event date Time before truncate=== 2021-03-09T20:46:24.081Z ====Event date Time after truncate=== 2021-03-09T20:46:24Z Answer The Z is the timezone information. You can convert the OffsetDateTime

How to round off to the closest 5 minute interval if it is 1 or 2 minutes ahead or behind?

I want to round off an Instant / LocalDateTime to its closest 5 minutes interval in Java. Examples: Suppose the time is: 2021-02-08T19:02:49.594 Expected result: 2021-02-08T19:00:00.000 Suppose the time is: 2021-02-08T19:03:49.594 Expected result: 2021-02-08T19:05:00.000 Similarly, if the time is: 2021-02-08T19:56:49.594 Expected result: 2021-02-08T19:55:00.000 Similarly, if the time is: 2021-02-08T19:58:49.594 Expected result: 2021-02-08T20:00:00.000 But if the time is 2021-02-08T19:55:00.000 or 2021-02-08T19:05:00.000

Advertisement