Currently we are using
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")
To format the time range to an external vendor for a range of data, for India, that formatter will give time like this:
2018-04-26T00:00:00.000+0530
However, my vendor say they cannot accept this format and it have to look like
2018-04-26T00:00:00.000+05:30
However, look like in DateTimeFormatter, whatever I choose Z/z/X/x, I don't get that format of offset. Just wonder is that a way to customize the offset to be HH:mm?
Or, I need to get the offset in second and work that our myself?
BASIC_ISO_DATE. The ISO date formatter that formats or parses a date without an offset, such as '20111203'. static DateTimeFormatter.
The DateTimeFormatter class in Java is used for parsing dates in different formats. You can use this class to format date in a specified format or you can use the predefined instances of DateTimeFormatter class.
Yes, it is: DateTimeFormat is thread-safe and immutable, and the formatters it returns are as well. Implementation Requirements: This class is immutable and thread-safe.
It is three x. Just tried with JavaRepl:
java.time.format.DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx")
.withZone(java.time.ZoneId.systemDefault())
.format(java.time.Instant.now())
Results in
java.lang.String res10 = "2018-04-27T11:06:50.648+00:00"
After some trial and error, I saw that this is also documented in the API documentation of DateTimeFormatter
but it is not easy to find (buried in a lot of other text):
Three letters outputs the hour and minute, with a colon, such as '+01:30'
DateTimeFormatter API Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With