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 DateTimeFormatterBuilder()
.appendPattern("MM/dd/yyyy ")
.appendPattern("HH:mm:ss")
.toFormatter(Locale.ENGLISH)
.withResolverStyle(ResolverStyle.SMART);
// Get the current time in the GMT timezone
LocalDateTime currentTime = LocalDateTime.now().withNano(0);
String sDFM = currentTime.atZone(TimeZone.getTimeZone("GMT").toZoneId())
.format(formatter);
debugLog(" time to use for token is: " + sDFM);
Perplexing as it is (to me), this does not always work, just enough to make me think its solved and then bang…. It fails.
Here are some log file entries which have the websphere log time at the left in UTC and the time returned by the above code on the right:
Line 243479: [5/31/23 23:07:39:596 UTC] 00000156 SystemOut O 31 May 2023 23:07:39:596 [DEBUG] [MXServer] [] MFA time to use for token is: May, 31 2023 23:07:39
Line 358120: [5/31/23 23:30:55:926 UTC] 00000159 SystemOut O 31 May 2023 23:30:55:926 [DEBUG] [MXServer] [] IAMFAUtil time to use for token is: 05/31/2023 23:30:55
Line 568091: [6/1/23 0:26:39:967 UTC] 00000158 SystemOut O 01 Jun 2023 00:26:39:967 [DEBUG] [MXServer] [] MFA time to use for token is: June, 01 2023 24:26:39
Line 568178: [6/1/23 0:26:40:611 UTC] 00000158 SystemOut O 01 Jun 2023 00:26:40:611 [DEBUG] [MXServer] [] MFA time to use for token is: June, 01 2023 24:26:40
I also sometimes get another time in some other zone that says 5am (occasionally) This happens just frequently enough that everything stops working … New note: I didn't expect an output of "24:26:40" ever, I expected 0-23 for the hour (first segment of the output), i.e. pattern HH instead of pattern kk. I will retest to verify I am not misleading anyone here and get back. Thank you for your time and thoughts.