Zone Date Time Format error
AnsweredHi Team,
In our JOB SDK code, one of our query will be fetching a binders which created in between particular interval of time.
so below is the logic we using,
Every time job runs it will fetch the current time using ZonedDateTime.now() it will fecth the date time in "2022-04-25T17:31:00.016Z[GMT]" format.
But expected format is "2022-04-25T17:31:00.033Z"
So to match the expected format we are converting the zoned date time to string and then using substring to remove zone id[GMT].
String Current_Time = Current.toString().substring(0,24)
Its working as expected but when a miili sec has 000 combinations, while converting it to string its ignoring 000s this causing datetime format exception.
let us know is there any way we can format the zoned date time without ignoring zeros ASAP.
Thanks you--
-
Official comment
Hi Pavithra,
When you convert the ZonedDateTime to a String, instead of using toString().substring, I would recommend using a DateTimeFormatter. For example:
ZonedDateTime now = ZonedDateTime.now();
String stringNow = now.format(DateTimeFormatter.ISO_INSTANT);Here is the documentation:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
Please sign in to leave a comment.
Comments
1 comment