I have an instant field and trying to validate the values in this field using the following approach: Instant.parse(“2021-09-29 09:35:07.531”) However, it throws the error: java.time.format.DateTimeParseException: Text ‘2021-09-29 09:35:07.531’ could not be parsed at index 10. So, how …
Tag: datetime
How to store ZonedDateTime of java in TIMESTAMPTZ in oracle?
I want to store the ZonedDateTime in TIMESTAMP WITH TIME ZONE datatype in oracle. If I am trying to store string directly as a String it throws not a valid month. then I found that I can convert it to the TIMESTAMPTZ in java then store because we need to convert the string to TIMESTAMPTZ and its throwing erro…
Subtract number of days without impacting the time
I have the following piece of code. I’m trying to get the epoch value t for exactly 10 days ago, at the current time. But when I convert t back to a date/time using https://www.epochconverter.com/, the printed result’s time is not correct. What am I missing? Answer I suggest you use OffsetDateTime…
Ethiopian calendar in Android
I am developing an Android app for an Ethiopian company and have to deal with dates. The calendar used in Ethiopia is similar to the Gregorian one but has two main differences: it’s set approx. 7 years earlier and has 13 months. At the time I post this question the date is 13-09-2021 in the Gregorian ca…
Java DateTime output formatter equivalent to Calender.getInstance method
I am trying to replace old java Date with new DateTime. I am running the below code to check various formats: This is the output I got : I want to format the output for LocalDateTime/ZonedDateTime in such a way that it is equivalent to the Calender output. But I am unable to achieve that. Can someone help. Th…
Unable to find Dateformat
I know this is a very silly question but I’m unable to find a suitable dateformatter for the given Date: 2020/04/01T20:00-05:00 or 2020/03/05T21:45-07:00. Any sort of help would be highly appreciated. Answer You can’t find one because that is a non-standard format. – is industry standard, us…
How to get perfect UTC Time in java/android?
I am trying to get UTC time in my application but unfortunately every time I am getting my current emulator Date and Time Instead of UTC. Tried, Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(“UTC”)); ZonedDateTime utcTime = ZonedDateTime.now(ZoneOffset.UTC); DateTime now = DateTime.now(…
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 So…
Formatting ZonedDateTime for previous years
I am trying to format MM/dd/YY into uuuu-MM-dd’T00:00:00Z. I have the following code. String dateTime = “12/10/20”; DateFormat df = new SimpleDateFormat(“MM/dd/yy”); Date date; …
How to get object from list with maximum date time object
Below is my code to find the contact object with the latest begin dateTime. DateTime is shown as an object. Is there any method to simplify this code using streams and comparators. Answer I’m assuming that begin is a java.util.Date or any other Comparable? Then you could do: