Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
206 views

Year, month, day, hours, minutes to Date without "magic"

Let's get this over with. How do you convert a LocalDateTime to a java.util.Date without any "magic tricks" pulled by Java (which are becoming less and less amusing to me)? The year, month, ...
Cagepi's user avatar
  • 153
0 votes
1 answer
104 views

How to mock LocalDateTime.now(ZoneId.of(“America/New_York”)) with mockito4.5.1?

When I unit test for LocalDateTime with jdk 17, follow exception occurred. java.time.zone.ZoneRulesException: Invalid binary time-zone data: TZDB:America/New_York, version: 2024a here is my code: ...
Chenglin Zhao's user avatar
2 votes
2 answers
87 views

DateTimeParseException when parsing 01-FEB-25 12.00.00.000000 AM UTC, where is the issue?

I have the following Java (version 8) code that parses a date time string that looks like '01-FEB-25 12.00.00.000000 AM UTC'. Expected result is a ZonedDateTime of 2025-02-01T00:00Z[UTC]. But I keep ...
isoplayer's user avatar
  • 103
0 votes
2 answers
92 views

Calculate calender days between two dates in java

is there any way to calculate calendar days between two dates. I tried with below code but looks like it gives 1 day as answer. But I am expecting the difference between this date is 2 days. No need ...
JAVA_CAT's user avatar
  • 849
-2 votes
1 answer
57 views

How to convert the Integer timestamp to date format and compare with LocalDateTime.now? [duplicate]

I have receive a timestamp in request as Integer format target_time = 1728962183 Then I want to use it to compare with LocalDateTime.now() to decide the code flow. Exp: if(target_time < ...
Bing Hao's user avatar
2 votes
2 answers
220 views

What's the difference between TimeZone and ZoneId?

What is the difference between the java.util.TimeZone and java.time.ZoneId classes in JDK? Is there more information about the differences between the two to help me decide which class I should use in ...
Xi Minghui's user avatar
0 votes
0 answers
138 views

DateTimeFormatter get local time instead of using hard coded time zone

I have these 2 lines: DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")).withZone(ZoneId.of("UTC")); String s = dateFormatter.format(Instant.now()); ...
grunt's user avatar
  • 712
5 votes
1 answer
131 views

Does Java's DateTimeFormatter allow lenient parsing for fractional seconds?

I am currently working with Java's DateTimeFormatter to parse ISO 8601 formatted timestamps, particularly those containing fractional seconds. While experimenting with different timestamp formats, I ...
Ayush Jain's user avatar
2 votes
1 answer
98 views

DateTimeParseException for LocalDateTime object despite having the format mapped

I have a Java 8 application that has to accept any number of date and time formats from a user. Obviously that yields an exhaustive list, as there are many ways to write a date and time. For locale ...
S Hornby's user avatar
  • 115
0 votes
0 answers
86 views

Slick 3.5.1 LocalDateTime parser taking only 3 nanosecond numbers

I am using scala slick library 3.5.1. I have implemented DB tables for Oracle profiles with LocalDateTime columns. When trying to select data, insert data I am getting ORA-01830: date format picture ...
M. Barabas's user avatar
-1 votes
2 answers
34 views

How do i solve extra time unit using LocalDateTime?

I have 3 drop down menu to choose startTime, interval and endTime. Based on these threes, i wanna generate list of time units for nextIntakeTime for medicines. It works fine for smaller times like: ...
Himel's user avatar
  • 1
3 votes
0 answers
87 views

Kotlinx LocalDate custom formatting

I am investigating the kotlinx DateTimeFormat and have multiple format use cases in my application which are all using the standard LocalDate.Format{} as shown below: val formatter: DateTimeFormat<...
RichardMillhouse's user avatar
0 votes
1 answer
81 views

Getting the YearMonth values between two LocalDate [duplicate]

I have two LocalDate values. Say: LocalDate startDate = LocalDate.of(2020, 1, 1); LocalDate endDate = LocalDate.of(2024, 1, 31); I need to determine the actual month values (in a List, for example) ...
Stan Ostrovskii's user avatar
0 votes
3 answers
224 views

Comparing if a Instant has passed a Duration in java

Problem I am currently trying to fix an issue with my Java Code. Essentially, I have to variables: currentTime of Type Instant and activeAfterSecond of type Duration (from the java.time package). ...
Palucca's user avatar
  • 35
3 votes
1 answer
111 views

Kotlin parsing date which is in format - Jan 1 2023 12:00AM to 2023-01-01 00:00:00.0

It appears that Kotlin is very specific regarding the formats of Date. I am receiving a string in this "Jan 1 2023 12:00AM" and wanted to convert it into this "2023-01-01 00:00:00.0&...
Karan's user avatar
  • 854
2 votes
1 answer
280 views

How do you display AM or PM using a time picker in jetpack compose?

I've developed a simple time picker app in jetpack compose. It consists of a text composable and a time picker. The text displays the selected time. However it doesn't display whether it is AM or PM. ...
Bob Rasner's user avatar
-3 votes
1 answer
96 views

Java Efficient Conversion of LocalDateTime to byte[] [closed]

I need to read a database table (sorted rows) with 300+ million TIMESTAMP as LocalDateTime in Java, and I need to get a single hash of all of them. Then, I need to get the same hash from the migrated ...
Joe DiNottra's user avatar
4 votes
1 answer
106 views

How to get Java 8 time classes to work on Jersey Jax-RS clients?

You can tell how to configure ObjectMapper to automatically handle LocalDateTime class covered here: serialize/deserialize java 8 java.time with Jackson JSON mapper But when I try to use POJOs with ...
Nicholas DiPiazza's user avatar
-1 votes
1 answer
146 views

Changing time zone doesn't make LocalTime.now() returns different value, why?

Recently I created a VM on Google Cloud Platform to run my .jar 24/7, and a part of my code is like: if (LocalTime.now().getHour() == 0) whenDateChanged(); I noticed that it runs at 12 am UTC+0, ...
Alex Cai's user avatar
-1 votes
2 answers
297 views

Exception in thread "main" java.time.format.DateTimeParseException: Text 'Apr 1 2022 12:00:00:000AM' could not be parsed at index 19 [duplicate]

I've date format like Apr 1 2022 12:00:00:000AM and looking to convert it into 20220401 (yyyyMMdd).How can we convert the Date format import java.time.LocalDateTime; import java.time.format....
PAA's user avatar
  • 11.9k
3 votes
2 answers
122 views

How to use the Instant Class in Java to get Elapsed Time in Seconds to a Certain Number of Decimal Points? [closed]

Is there any way to use the Instant class in Java to get elapsed time in seconds to a certain number of decimal points? I took some time to experiment, and I was able to to use the .now() method at ...
ChicoTabi's user avatar
2 votes
1 answer
145 views

Java Time: plus days on UTC date/time changes the hour

Consider the following: import java.time.*; var today = Instant.now(); var futureDay1 = today.atZone(ZoneId.systemDefault()).plusDays(1428826726); var futureDay2 = today.atZone(ZoneOffset.UTC)....
Mauro Molinari's user avatar
1 vote
2 answers
327 views

Which datatype to use at JPA entity to store and retrieve date using java 8

I am using java 8 version in my application, I have confused to use java date classes like java.util.Date and java.time.LocalDate at entity and dto level. Before java 8, we used to use either java.sql....
Anil Nivargi's user avatar
  • 1,717
1 vote
1 answer
153 views

Why is java.sql’s Timestamp.of() converting incorrectly from java.time’s LocalDateTime?

I ran into a bug where java.sql's Timestamp.valueOf(LocalDateTime.MIN()) is converting incorrectly. Given java.time's LocalDateTime.MIN() = -999999999-01-01T00:00:00 But when I try to convert it ...
thekinggpin's user avatar
1 vote
1 answer
42 views

Swagger Implementation for LocalDateTime type

I want to create a model class that contains createdDate feild type as LocalDateTime using swagger contract, when implementing using swagger contract it is generating offsetDateTime as type in dto. ...
Keerthi's user avatar
  • 11
1 vote
2 answers
111 views

How to make hours optional in ISO_LOCAL_TIME formatter

I'm trying to make the hours 1 or two digits and optional by modifying the ISO_LOCAL_TIME formatter. This is for parsing durations where hours can be optional. This is what I tried. new ...
John Mercier's user avatar
  • 1,705
2 votes
1 answer
68 views

Bind saved Date in Edit Form using Angular 17

I have a form where the date is entered and saved but the date is not binded when I go to edit the form. JSON: "checkOut": { "runDate": "2024-07-05T09:42:00.000Z", } ...
Elaine Byene's user avatar
  • 4,142
0 votes
1 answer
61 views

Spring Boot and Batch Processor Item Date field is null

Spring batch using JdbcCursorItemReader for reader. and .setSql("select * from EMPLOYEE") Employee entity has a Date filed @Column(name = "CREATE_DATE_TIME") private LocalDateTime ...
Manu's user avatar
  • 1,263
0 votes
1 answer
56 views

Spring getting validation error with pattern dd-MM-yyyy

I have a LocalDate field of an entiry class as below. @DateTimeFormat (pattern="dd-MM-YYYY") private LocalDate myDate; I have a Date object when printed displays Thu Jul 07 00:00:00 IST ...
itsraja's user avatar
  • 1,726
0 votes
1 answer
97 views

Are there tools like Jqwik for easily testing Google API's time class? (DateTime, EventDateTime...etc)

I was working on implementing test code for Google Calendar-related logic and came across a library called Fixture Monkey. To briefly explain, Fixture Monkey is a library that facilitates the creation ...
Kevin's user avatar
  • 742
0 votes
1 answer
55 views

Using LocalDateTime in Java Spring framework, still gives Date,parse() error for MongoDb collection

I want to generate a listing report based on "listing status" and "createdOn" date on the MongoDB collection"processing-status". The "listingStatus" field ...
Arti M's user avatar
  • 21
0 votes
0 answers
102 views

java.util.Date converted to LocalDate returns Strange results [duplicate]

Date date = new Date(); Calendar cal1 = Calendar.getInstance(); cal1.set(Calendar.YEAR, 0001); cal1.set(Calendar.DAY_OF_MONTH, 1); cal1.set(Calendar.MONTH, Calendar.JANUARY); cal1....
Rohit's user avatar
  • 665
0 votes
0 answers
57 views

JOOQ removing milliseconds precision for Instant field (MariaDB)

I have a problem with conversion of java.time.Instant and java.time.LocalDateTime to SQL Timestamp using JOOQ. Currently I am populating field as: setField(MODIFIED_AT_FIELD_NAME, Instant.now(), ...
user3801003's user avatar
1 vote
1 answer
84 views

LocalTime parse truncating time's second value

I have similar issue to this.There is no solution there and I am not working with JSON mapping. LocalTime.parse on time string is removing second part. I have put the test code below. Any suggestion? ...
αƞjiβ's user avatar
  • 3,236
1 vote
2 answers
308 views

Time zone day light saving changes problem

In my country, we no longer observe Daylight Saving Time. We now use Standard Time year-round. Therefor a lot of devices has run into problem. I used different approaches to fix this but just one of ...
Farid's user avatar
  • 1,088
0 votes
2 answers
177 views

Funky behavior when calling System.out.println from virtual threads

When running an example program that calls the System.out.println method from java's new virtual threads, I am getting some weird results. Here's the sample program: import java.math.BigInteger; ...
user9532210's user avatar
1 vote
0 answers
249 views

How to store an Instant in a database (Oracle) with Hibernate/JPA

After reading different blogs and stackoverflow articles I still don't get it. In my application I have an Instant and I want to store this instant in a database without messing around with it at all. ...
olijaun's user avatar
  • 11
-3 votes
1 answer
100 views

LocalDateTime Conversion [duplicate]

I am trying to convert current date and time with the help of LocalDateTime java class and then trying to store it in Database table column having Date datatype. Below is the code , i am trying to ...
Rahul.V's user avatar
1 vote
0 answers
63 views

How come java.time.zone.ZoneRules requires to generate timezone transitions?

In java 21 (available since java 8) there's a static factory method java.time.zone.ZoneRules#of which is the suggested way to create custom timezone definitions that would later be provided via ...
Dragas's user avatar
  • 1,287
3 votes
0 answers
52 views

Is there a way to canonicalize time zone IDs using the java.time APIs?

Some time zones are aliases for other time zones. For example, at the time of writing, Europe/Skopje and Europe/Zagreb are linked to Europe/Belgrade. In Joda Time, these aliases can be resolved by ...
Malcolm Rowe's user avatar
4 votes
3 answers
123 views

Unable to Parse time in format hhmmss to LocalTime in Java [duplicate]

I am trying parse '093000' as follows in java: LocalTime parsed = LocalTime.parse("093000", DateTimeFormatter.ofPattern("hhmmss")); However I am running into this exception and ...
CS1999's user avatar
  • 429
2 votes
1 answer
46 views

One date time formatter for 2 cases

I am trying to parse a date in format yyyyMMddHHmmss. The problem is that 'ss' part is optional so '202308301000' and '20230830100005' are acceptable. I defined my formatter like this: private ...
luki27's user avatar
  • 91
0 votes
1 answer
72 views

Java DateTimeFormatter problems

I have the following method, which takes a date string and tries for formate it to a LocalDateTime object: (Locale is Norwegian) public static LocalDateTime parseDatoLocalDateTime2(String datoString, ...
kakemonsteret's user avatar
0 votes
0 answers
27 views

Not able to serialize ZonedDateTime and PeriodDuration while converting a bean to XML

I used Joda-Time earlier. Now, I have migrated from DateTime(Joda-Time) to ZonedDateTime(java.time). I have also converted Period(Joda-Time) to PeriodDuration(Java). But as ZonedDateTime and ...
Saurabh Sole's user avatar
0 votes
1 answer
277 views

Java 8 date/time type not supported by default - when using RestEasy client POST request

I am using RestEasy client POST request as in the following interface: @POST @Path("/somePath") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response ...
idan's user avatar
  • 1
1 vote
1 answer
50 views

Count half hours since midnight Europe/London

I have a seemingly simple task, I wish to solve it in pure Java 21 - although will use a library if I must. I need to count the number of completed half hour intervals, from midnight on the same day - ...
Boris the Spider's user avatar
0 votes
2 answers
464 views

ChronoUnit.DAYS.between returns wrong number of days between two java.time.LocalDate objects [closed]

public static long getDaysBetween(Record record) { if (record == null || record.getRecordedDate() == null) { throw new RuntimeException("Unable to extract update date from record"); } ...
user1544358's user avatar
0 votes
1 answer
224 views

Egypt time zone java and joda libraries updated before DST 2023 does that need an update for 2024 DST

We are having a system running on servers having EET time zone, In 2023 before DST changes in Egypt, Java (jre8) and Joda(2.12.5) libraries were updated and it worked fine with EEST time zone. this ...
Jatin Bodarya's user avatar
0 votes
1 answer
37 views

Saving time to database in the absence of Zone information

I process a TEXT log file that contains, among other items, date in this form: 'January 20, 2021 5:26:19 pm'. I don't have zone information. The system runs in complete isolation, such as offline mode,...
user1860447's user avatar
  • 1,436
1 vote
0 answers
96 views

The app crashes when converting LocalDate to a string value with the format "yyyy-MM-dd", but works with "yyyy-MM-DD"

I'm trying to convert the returned date from a calendar into a string value, but it has an unwanted number. I've made a text that views the selected date value for today, and it's successfully printed ...
Mahmoud Nabil's user avatar

1
2 3 4 5
37