2,066 questions
Advice
0
votes
13
replies
178
views
How to replace Joda dateTime and interval with Java.time
I am trying to replace Joda datetime and interval methods with Java.time and also trying to specify explicitly timezone as Duser.timezone=America/Chicago.
This my code fragment
public void ...
2
votes
0
answers
81
views
how to implement a ConversionService from LocalDateTime to String in spring boot
I have a spring boot webapp, which uses thymeleaf for html templating and as templating engine for emails sent by this webapp, too. In my email I want to use a LocalDateTime, which does not work.
...
4
votes
1
answer
585
views
What is the difference between withLocale() and localizedBy() in Java DateTimeFormatter?
DateTimeFormatter
Java 8 introduced a modern date and time API with new types like LocalDate available in java.time.* package. It also provided a new DateTimeFormatter class for formatting (generating ...
9
votes
7
answers
1k
views
Given a whole hour of the day, how to find the next whole hour?
I need to iterate through the whole hours of an interval of a particular day. So given the time at one whole hour on the day in question, say, 01:00, how do I find the next whole hour? The next whole ...
0
votes
0
answers
80
views
Unable to write JSON:Java 8 date/time type java.time.LocalDateTime when using Hateos Json API [duplicate]
I am working on Spring Hateos Json APi.
I have a Get request
import static com.toedter.spring.hateoas.jsonapi.MediaTypes.JSON_API_VALUE;
import org.springframework.hateoas.EntityModel;
import java....
-1
votes
3
answers
190
views
Migrating from Joda-Time to java.time: How to replace time.toDateTimeToday().getMillis()? [closed]
I'm currently migrating my codebase from Joda-Time to the java.time API (Java 8+).
In one part of my application, I schedule tasks to run at a specific time either today or tomorrow, depending on ...
2
votes
4
answers
238
views
How can I truncate time to tenths of a second?
In Java, I can easily truncate a temporal value (LocalTime, ZonedDateTime, etc.) to seconds, milliseconds, or any other value that has an existing ChronoUnit defined:
LocalTime time = LocalTime.now();
...
0
votes
1
answer
129
views
Java LocalDateTime Serialized output is giving incorrect values
I am working on replacing crnk with Spring Hateos Json APi . I was getting a exception for LocalDateTime so I have used
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using =...
-1
votes
1
answer
166
views
DateTimeFormatter with "yyyy-MM-dd HH:mm:ss" parses into LocalDateTime with missing seconds [duplicate]
I'm updating my code to use java.time.format.DateTimeFormatter instead of java.text.SimpleDateFormat and now a test fails which didn't before. When I parse the String
2010-12-31 00:00:00
, which in my ...
4
votes
3
answers
213
views
Why does parsing with this DateTimeFormatter throw an exception?
Both of these DateTimeFormatters are nearly identical, however only the second one throws an exception. Both of these patterns are valid as far as I can tell.
Why does changing minWidth cause parsing ...
6
votes
4
answers
229
views
Not able to parse P10YT10M ISO-8601 duration string in java
I am trying to parse durationString= P10YT10M using java.time.Duration.parse() method, but it fails with "Text cannot be parsed to a Duration".
try {
String durationString = "...
0
votes
0
answers
27
views
Jasper Studio crossTab, rowGroup DateTime to "Month Year"
I have been struggling to get my crossTab to group by "Month Year". I read that SimpleDateFormat is outdated. My dataset is using language domain.
The coding is html style and lots of ...
5
votes
1
answer
191
views
Reading a string in java to proper Date format [duplicate]
I have a string:
String inputDate = "18-FEB-24 10.02.33.578000000 AM";
I am trying to read it back and format it in YYYY-MM-DD HH:mm:ss.SSSSSS.
I tried the SimpleDateFormat as well as ...
-4
votes
2
answers
405
views
Add timezone to java.time.OffsetDateTime
I have this Joda-Time date which I want to migrate to java.time.OffsetDateTime:
import org.joda.time.DateTime;
private DateTime createdDate;
private String creationTime;
.....
DateTimeFormatter dtf = ...
0
votes
0
answers
40
views
java.time.ZonedDateTime error on JSON conversion to object [duplicate]
I am converting a JSON to an object and it's giving me the following error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type java.time.LocalDateTime not supported ...
0
votes
1
answer
293
views
could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor
I have this java code:
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;
DateTimeFormatter DATE_TIME_FORMATTER
= DateTimeFormat....
3
votes
3
answers
122
views
Add a fixed amount of minutes to a Java LocalTime in a for-loop until midnight without causing an infinite loop
Given a LocalTime add n minutes to it untill midnight and print those times to console. Example:
public static void main(String[] args) {
LocalTime start = LocalTime.of(10, 12, 0);
...
6
votes
3
answers
241
views
Is there a java.time equivalent of DateTime.dayOfYear().isLeap()?
We have some code which checks whether a given day is a leap day using org.joda.time. It is simply
import org.joda.time.DateTime;
DateTime date;
return date.dayOfYear().isLeap()
Is there an ...
2
votes
1
answer
245
views
Is there any pattern to format and parse periods in a day, such as 'in the morning', 'in the afternoon' or 'at night'?
I want to express periods in the day, such as in the morning, in the afternoon, or at night, not just AM or PM.
Is there any pattern in java.time API to format and parse periods in a day, such as in ...
1
vote
1
answer
234
views
Custom time deserialization with Jackson
I need to handle an older set of data files, where among other infos, a local data time was serialized to the form
"timeOfAcquisition":[2024,8,13,9,49,52,662000000]
Younger files will ...
0
votes
2
answers
464
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, ...
0
votes
1
answer
255
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:
...
2
votes
2
answers
105
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 ...
0
votes
2
answers
140
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 ...
-2
votes
1
answer
72
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 < ...
4
votes
2
answers
761
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 ...
0
votes
0
answers
177
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());
...
5
votes
1
answer
525
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 ...
2
votes
1
answer
111
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 ...
0
votes
0
answers
96
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 ...
-2
votes
2
answers
48
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: ...
0
votes
1
answer
168
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) ...
0
votes
3
answers
1k
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).
...
3
votes
1
answer
158
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&...
3
votes
1
answer
683
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.
...
-3
votes
1
answer
153
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 ...
4
votes
1
answer
156
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 ...
-1
votes
1
answer
184
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, ...
-1
votes
2
answers
436
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....
3
votes
2
answers
212
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 ...
2
votes
1
answer
214
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)....
1
vote
2
answers
1k
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....
2
votes
1
answer
334
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 ...
1
vote
1
answer
53
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.
...
1
vote
2
answers
138
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 ...
2
votes
1
answer
85
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",
}
...
0
votes
1
answer
69
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 ...
0
votes
1
answer
67
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 ...
0
votes
1
answer
131
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 ...
0
votes
1
answer
83
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 ...