jean
01/26/2022, 10:21 AM2021-11-29T23:00:00.000+0000
to it’s equivalent in another time zone?
I tried this :
internal fun String.localDateTime(): LocalDateTime = Instant.parseWithBasicOffset(this) //parseWithBasicOffset is a custom parse due to time zone written without ":"
.toLocalDateTime(TimeZone.currentSystemDefault())
but myString.localDateTime().toString()
returns 2021-11-30T00:00
the date is correct but I lost the time zone there, which I need for further processing.
So my question is : how do I go from 2021-11-29T23:00:00.000+0000
to 2021-11-30T00:00:00.000+0100
(or eventually +01:00
)Desmond van der Meer
01/26/2022, 10:48 AMLocalDateTime
is inherently without time zone, because it literally just points to a date and time. You can combine it with a timezone to get an Instant
back, but that will just result in the instant you started with.Desmond van der Meer
01/26/2022, 10:52 AMInstant.toString()
. But you could create the string yourself using TimeZone.offsetAt()
.ilya.gorbunov
01/30/2022, 6:43 PMtoLocalDateTime()
when you need to get their representation in a particular time zone or offset.jean
01/31/2022, 9:11 AMdate -> consumptions
per predefined period for each compared days/months. After that I was trying to convert utc dates to local zone then to string to be able to group them by relevant criteria (value of the day if days we compared, or value of the month if months were compared). Since the month or day value of the first day of the month depends on the timezone when converted to a string (issue I posted originally) I was trying to convert it to the local value string. But I figured out I could simply use the Instant string without timezone to do so. All in all, I did not need the local string with the timezone value 🙂