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 – this is specially for the UK electricity market and there are specific rules… Read More Count half hours since midnight Europe/London

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 resolved to 01:43:56 of type java.time.format.Parsed I’ve tried every variation of the time format I can think of: LocalDateTime.parse("01:43:56", DateTimeFormatter.ofPattern("hh:mm:ss")) LocalDateTime.parse("01:43:56", DateTimeFormatter.ofPattern("HH:mm:ss")) LocalDateTime.parse("01:43:56", DateTimeFormatter.ofPattern("H:mm:ss")) LocalDateTime.parse("01:43:56", DateTimeFormatter.ofPattern("H:m:s"))… Read More Cannot parse time string to LocalDateTime

Migrate org.joda.time.Duration to java.time.Duration

I want to migrate this java based on joda library to java.time import org.joda.time.DateTime; import org.joda.time.Duration; import org.joda.time.Instant; private DateTime createdDate; private Duration executionTime; private Instant requestTime; public void startTimerProcess() { this.requestTime = Instant.now(); } public void endTimerProcess() { this.executionTime = new Duration(requestTime, Instant.now()); } I tried this: import java.time.Duration; import java.time.Instant; import java.time.OffsetDateTime; private… Read More Migrate org.joda.time.Duration to java.time.Duration

Java DateTimeFormatter can't format its own parsed TemporalAccessor

I’m creating a simply DateTimeFormatter, but it can’t seem to read it’s own output. The reason I need to use the DateTimeFormatter directly and not LocalDate.format or YearMonth.format is that the code needs to be generic enough to handle different instances of DateTimeFormatter with completely different fields. The code below fails with: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field:… Read More Java DateTimeFormatter can't format its own parsed TemporalAccessor

Difference between the full name of Time zone and the abbreviation

I have multiple times in my database that look like this: String summerTime = "2022-07-21T10:00:00Z"; String winterTime = "2022-11-21T10:00:00Z"; In another hand, I want to get the time part of these dates based on a custom timezone, the timezones that I have, look like this: GMT-03:00 GMT-02:00 GMT-01:00 GMT+02:00 GMT+01:00 …. When I try to… Read More Difference between the full name of Time zone and the abbreviation

parse custom time in java 8

I want to create a one utility method that parses custom time strings like: 14h , 17h30. I tried to use LocalTime.ofPattern() method using various pattern combination but I keep getting a DateTimeParseException Edit: I tried the following: This throws an exception when the time is 14h LocalTime time = LocalTime.parse("14h", DateTimeFormatter.ofPattern("k’h’m")); And this also… Read More parse custom time in java 8

ZonedDateTime America/Phoenix zone to GMT having issue

I want to Convert America/Phoenix to GMT ZonedDateTime zdtPhoenix1 = ZonedDateTime.of(2022, 6, 27, 10, 0, 0, 0, ZoneId.of("America/Phoenix")); System.out.println(zdtPhoenix1); System.out.println(zdtPhoenix1.withZoneSameInstant(ZoneId.of("GMT"))); Out Put 2022-06-27T10:00-07:00[America/Phoenix] 2022-06-27T17:00Z[GMT] I am expecting GMT 2022-06-27T03:00Z[GMT] As ZoneOffset of America/Phoenix is -7 hours but the actual output is +7 hours >Solution : 10:00-07:00 is not an arithmetic expression. -07:00 means that your… Read More ZonedDateTime America/Phoenix zone to GMT having issue