Skip to content
Advertisement

Tag: datetime

Java Instant.parse cannot validate date

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 can I test if the given Instant date in String format is a valid Instant date? I am implementing an Import feature

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.now(ZoneOffset.UTC) to get the current Date-Time in UTC and

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 calendar and 03-01-2014 in

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, using timezone offsets is outdated. Thus, you’d have to make it yourself. But this

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(DateTimeZone.UTC); My code: Any help highly appreciated. Answer Try this code:

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?

Advertisement