Questions tagged [java-time]

The java.time package is a modern date-time framework that debuted in Java 8, defined by JSR 310, supplanting the java.util.Date and .Calendar classes. Inspired by Joda-Time, but re-architected. It uses the ISO 8601 standard as the default for parsing and generating strings and includes classes to represent date-only, time-of-day-only, and span-of-time values.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
68 views

Getting Error Text 'Time' could not be parsed at index 0 in when i'm trying to parse time

I'm trying to retrive date cell from my xlsx sheet in java and tying to formate the data in "MM/dd/yyyy" formate Cell celldate=row.getCell(2); String value=formatter.formatCellValue(...
mm m's user avatar
  • 59
0 votes
0 answers
39 views

Java Program issue with 24 hour time reset based logic and variables

I'm creating a basic java program that is a Wordle clone in the command line. My main issue is with teh lgoci of being able to allow the player a max of 10 games played per day with a 24 horus reset. ...
Rory Steuart's user avatar
0 votes
1 answer
85 views

Why Instant.parse() string with timezone behaviour in java8 is different than java 17

The following code snippet Instant.parse("2023-08-08T00:00:00+02:00") compiles and executes as expected in java-17. But when executed with java-8, throws the following exception java.time....
office.aizaz's user avatar
0 votes
1 answer
114 views

How to group and reduce a list of objects with duration

I want to create a list of persons sorted by LocalDate and String as well as aggregated by duration. I did some research regarding the use of duration in streams: How to get the average duration for ...
Mc_Android's user avatar
0 votes
1 answer
38 views

How to enforce a restriction of using Instant.now() or new Date() in any Java Test Methods?

Want to enforce a restriction of using Instant.now() or new Date() in any Java Method. Below is the sample class class Demo { void methodOne() { Date date = new Date(); // ... ...
Codinggeek's user avatar
5 votes
1 answer
88 views

DateTimeFormatter Validation for Existing Year, Optional Month, and Optional Day

We are attempting to write a single DateTimeFormatter that helps us validate an ISO 8601 that allows our end user's to enter just a year, a year and a month, or a year, month, and day. We also want ...
hooknc's user avatar
  • 4,922
2 votes
0 answers
209 views

com.github.msarhan.ummalqura.calendar.DateTimeException: Invalid Hijrah day of month: 30

I'm using msarhan library for Ummalqura calendar in my Android application , When I open the calendar and select day 30 and go to last day 29 in another month and select it , the application crash ...
Ahmed Elsayed's user avatar
1 vote
1 answer
75 views

How to find end of the day using epoch time and zone in Java

I have the epoch time of an event, as eventTime in seconds and the zone (location of the event) as userZone. I need to check if an event is eligible. An event is only eligible if it happens before the ...
Alan's user avatar
  • 431
0 votes
2 answers
92 views

Unable to obtain Instant from TemporalAccessor: 2023-08-31T20:37:49.005832800 of type java.time.LocalDateTime

I am using parmeterised method for Temporal class and passing LocalDateTime to Temporal argument and getting error in Instant.from(Temporal t) method where, t instancof LocalDateTime in my case. Here ...
gajesh's user avatar
  • 5
-3 votes
1 answer
44 views

how can I support more than 24hours of time format [closed]

I have a requirement to support more than 24 hours of time format, for example if the time is 25:15:00 then it should return 01:15:00, in java local Time API. I am unable to find solution for this can ...
Arushi awasthi's user avatar
2 votes
4 answers
119 views

How to make LocalDateTime.parse reject 24:00 time

I have a form where user can input date and time from keypad and LocalDateTime accepts input when time part of input is 24:00, converting it to next day. My code import java.time.LocalDateTime import ...
Algimantas's user avatar
-2 votes
1 answer
67 views

Unsupported argument value: 'YEARS'

I want to run this code: final LocalTime currentTime = LocalTime.now().plus(2, ChronoUnit.YEARS); long milliseconds = currentTime.toNanoOfDay() / 1000000; String s = Long.toHexString(milliseconds)....
Peter Penzov's user avatar
4 votes
1 answer
103 views

Fixed Clock and LocalDateTime

For testing purposes I want to create a fixed Clock with a time zone: Clock c= Clock.fixed(Instant.parse("2018-04-29T10:15:30.00Z"), ZoneId.of("Europe/Berlin")); //yields ...
user15110545's user avatar
0 votes
0 answers
34 views

Convert String value to OffsetDateTime [duplicate]

I have the following code: public class Objc{ OffsetDateTime purchaseDate = new OffsetDateTime(); // getter/setter } .... String buyDate = ......; objc....
Peter Penzov's user avatar
1 vote
2 answers
56 views

DateTimeFormatter with multiple pattern not working

Both of these patterns working fine when tested separately but they are not working together in a single ofPattern { "[]" + "[]"} statement. Please guide what am I missing here ...
Sahib Yar's user avatar
  • 1,020
1 vote
3 answers
90 views

Get a list of Monday dates from Broadcast calender between given range of dates using java

I have a date range Oct 7, 2024 to Dec 29, 2024. I need to fetch all the weeks start date of a broadcast calendar that is all Monday dates between this range. Trying to do something like below. I'm ...
raj's user avatar
  • 15
0 votes
1 answer
15 views

Jackson annotation to convert java.uti.Date to java.time.Instant

My rest service is calling another Rest API using sprint rest template. Java class corresponding to Request body has one field is of type Date (java.util.date) as application source is 1.6 java. Now ...
akr's user avatar
  • 123
0 votes
2 answers
75 views

How to add a custom serializer/format for Java zoneddatetime with fabric8 maven plugin?

I am using fabric8 maven plugin to autogenerate Java classes for a CRD from it's yaml file. One of the fields is: updated_time: format: date-time type: string It's getting converted to a java....
xerocool's user avatar
  • 113
0 votes
0 answers
54 views

List has custom object with overlap date ranges need to break all overlap ranges into new periods and keep non overlap AS IS in java

Consider below example , inputList has overlap date ranges inputList.add(new DateRange(LocalDate.of(2023, 7, 1), LocalDate.of(2023, 7, 10))); inputList.add(new DateRange(LocalDate.of(...
venu's user avatar
  • 11
0 votes
0 answers
34 views

ZonedDateTime output different on Android 13

I'm getting two different date outputs on different versions of Android ZonedDateTime.parse("Mon, 31 Jul 2023 18:57:55 +0000", DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId....
Kris B's user avatar
  • 3,436
0 votes
4 answers
79 views

Cannot parse time string to LocalDateTime

I'm trying to convert this string 01:43:56 to a LocalDateTime but keep getting this error thrown: Text '01:43:56' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO ...
Kris B's user avatar
  • 3,436
0 votes
2 answers
62 views

LocalDateTime format ok in JSON, not ok in database

I want to format date-times in a SpringBoot REST API I'm building in the format "dd/MM/yyyy HH:mm:ss.SSS". So I've put it in a global constant: public static final String ...
Jason's user avatar
  • 2,535
1 vote
4 answers
97 views

How to parse a date string containing a numerical zone offset

I have this date in string "Fri, 14 Jul 2023 11:53:06 -0400" and I am unable to convert it in LocalDateTime I have tried this pattern "EEE, dd MMM yyyy HH:mm:ss z" and I have date ...
akaliza's user avatar
  • 3,641
-1 votes
2 answers
55 views

Android changes the time zone set programmatically for UTC date string

Update: problem solved,there is no issue with the java code snipped I used, the problem was related to errors in the data set. The API I work on return flights departure times set with UTC format 2023-...
Vincent's user avatar
  • 1,653
-2 votes
1 answer
32 views

java.time not accounting for daylightsaving DST [closed]

I want to convert a not timezone and DST aware time to a timezone aware time, so I can convert it to UTC. java.time atZone does not include DST, so time is one hour off. time offset should be +2 hours ...
blablaX's user avatar
  • 11
1 vote
1 answer
64 views

DateTimeException: Unable to obtain ZonedDateTime from TemporalAccessor

I have a datetime column in mysql database (colum is called creation_date), everytime im going to save the entity that has that column I fill that column like so (it is a LocalDateTime in my java ...
BugsOverflow's user avatar
1 vote
0 answers
201 views

Spring Data JPA 3 auditing @CreatedDate of java.time.OffsetDateTime does not get populated

I am trying to add Spring Data JPA auditing in my application, specifically using @CreatedDate and @LastModifiedDate annotations. This is a Spring Boot 3 application. Using postgresql testcontainers ...
Mirza Prangon's user avatar
0 votes
0 answers
29 views

Kotlin LocalTime handle all different ways to parse AM/ PM

Have an issue that my backend can receive 4 different formats for localTime. One as a 24h clock (without AM/ PM), one as AM/ PM, another one as am/ pm and as last a.m/p.m. Was wondering what the best ...
MrAndre's user avatar
  • 821
0 votes
1 answer
103 views

java.time.Instant.now has more precision in java 11 compared to java 8 and how to get backward compatible

I've below code in java import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; ...
user51's user avatar
  • 8,927
1 vote
1 answer
71 views

Time Zone Related Issue

I have a scenario where I have to activate/deactivate a link based on the times assigned. Here a hotel needs to activate the link 48 hours before check-in (15:00 PM) and deactivate the same 5 hours ...
Debasish Mishra's user avatar
0 votes
0 answers
18 views

SQL: Epoch milliseconds timezone issue when using for BETWEEN statement

What is the correct way to use epoch for storing and querying in database? Currently what we want to do is use the device date time and store its epoch milliseconds in database. However we are getting ...
Bitwise DEVS's user avatar
  • 2,479
1 vote
1 answer
51 views

Short name for timezones from java.time.ZoneId

I am using java.time.ZoneId class to set system default timezone. I need to return the short name for the system timezone. If the server is in Asia/Kolkata, the short name returned is IT instead of ...
darecoder's user avatar
  • 1,508
1 vote
1 answer
51 views

Java LocalDateTime with offset

The task is to convert current date time to that format: 2023-06-28T12:00:01.545+0300 For this purporse I use the following approach: String currentDateTime = DateTimeFormatter....
Jelly's user avatar
  • 972
0 votes
0 answers
60 views

Getting java.time.format.DateTimeParseException: Text 'December 05, 2020 at 10:00:00 AM PDT' could not be parsed at index 17

I am trying to run the below code in IntelliJ IDE and getting the parsing exception whereas the code works on the online Java Compiler. Can somebody please help me understand what I am doing wrong? ...
Manisha Biswas's user avatar
0 votes
2 answers
43 views

java.time Duration.between produces zonedatetime exception

I'm trying to calculate the difference between an epoch miliseconds and the currenttime on local machine. I was hoping to use idiomatic java.time api with: val eventTime = LocalDateTime.ofInstant(...
dr jerry's user avatar
  • 9,798
3 votes
1 answer
73 views

Question about Instant.toEpochMilli mismatch between java8 and java11

This is my first post, so if I am not following all the rules and conventions please forgive me. I have this problem with this code, which gives different epoch time millis in java 8 and java 11. ...
Mathew Mani's user avatar
2 votes
3 answers
71 views

Is there any way to convert ZoneOffset to ZoneId in Java 8?

I am working on a project wherer i have limited zoneid and i am getting zoneoff set from front-end so that's why i want to convert time off set into zoneid in java. is there any way to convert ...
Ankitgiri2411's user avatar
2 votes
1 answer
108 views

java.time.Instant does not render on the consumer side

I am trying to send some information with Kafka. I have a class to handle this task. The class includes a private variable called "timestamp" of type Instant. When the timestamp is generated,...
User's user avatar
  • 58
-1 votes
3 answers
103 views

How to convert Timestamp in CDT Format to MM/DD in Java?

I have a timestamp in cdt format as below "2023-06-05T09:00:01CDT", I want to convert this timestamp into MM/DD format in Java. I have tried below : The expected output was: 6/5 But was ...
BugEater's user avatar
0 votes
1 answer
107 views

Gson serializer for ZonedDateTime from java.time [duplicate]

I use Retrofit2 with Gson. I wrote a custom serializer for ZonedDateTime but it's not working. When I try to debug sending requests to the server, I see that the bugger does not enter the serialize ...
tasjapr's user avatar
  • 666
0 votes
0 answers
58 views

java time inconsistently reporting results

I have this code which is part of building a JWT token using a string in a certain format that should represent the current time in the GMT timezone: DateTimeFormatter formatter = new ...
kishjeff's user avatar
  • 121
2 votes
1 answer
36 views

How can I debug java.time classes in an Android app with desugaring enabled?

In the app that I develop we use ZonedDateTime and some other classes from java.time package very often. And from time to time there is a need for debugging. I am facing such problems as: ...
Inliner's user avatar
  • 1,161
0 votes
1 answer
152 views

Java UTC String to Paris Time

From this time : String date = "2023-01-31T23:00:00.000Z"; Which is in zulu time (UTC). How can I get the LocalDateTime in Paris time ? which can be UTC+1 or UTC+2 depending on the offeset ...
AyoubMK's user avatar
  • 526
1 vote
1 answer
53 views

I need to exclude Saturdays and Sundays from this program that shows dates of every 15 days

I'm trying to make a program that shows dates of every 15 days. import java.time.*; import java.util.Scanner; ; public class test{ public static final String ANSI_RESET = "\u001B[0m"; //...
Avighna Guha's user avatar
-1 votes
1 answer
1k views

How do I convert a Java Date into an Instant for a given timezone? [closed]

I have an instance of the Date class and a time zone (e.g Europe/London). How do I convert this into an Instant? Is the below the correct way of doing this? LocalDateTime localDateTime = LocalDateTime....
kcon123's user avatar
  • 470
0 votes
0 answers
43 views

How to resolve the JodaTime serailization issue with kafka?

I have two microservice, say service1 and service 2, now when i am sending the dto to kafka topic and want it to be consumed in both service which is happening as expected, but the problem is when it'...
Rupesh's user avatar
  • 850
0 votes
3 answers
156 views

Java ZonedDateTime MST to UTC conversion uses daylight savings

I need to convert the timestamp to UTC. Timestamp has the MST timezone, which is specified in the timestamp Examples of observed conversions: 2023-03-20 08:53:19 MST -> 2023-03-20T14:53:19 (-6)...
Dima Garbar's user avatar
-1 votes
1 answer
136 views

Unable to obtain LocalDateTime from TemporalAccessor: when trying to sort the date in the stream

I want to sort the posts by date("hh:mm:ss"). but I get a mistake. Can you tell me what I did wrong? java.time.format.DateTimeParseException: Text '12:55:36' could not be parsed: Unable to ...
R Zav's user avatar
  • 29
1 vote
1 answer
52 views

Display DateTime with additional zoneOffset value if Zone is present

While displaying the datetime in specific format is it possible to add the offset value to the hour and date Example: Let Say Date Time is 5/12/2023 23:18 PM is stored without any timezone in DB. Is ...
Thilakraj's user avatar
0 votes
1 answer
38 views

Json Date format in LocalDate

I have this annotation @Target(ElementType.METHOD) @Retention(value = RetentionPolicy.RUNTIME) @JacksonAnnotationsInside @Documented @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-...
Nuñito Calzada's user avatar

1
2 3 4 5
35