hey, I have a method that get the time of shanghai
Copy code
val CURRENT_TIME_ZONE = TimeZone.of("Asia/Shanghai")
fun shanghaiNow() = Clock.System.now().toLocalDateTime(CURRENT_TIME_ZONE).toInstant(UtcOffset(hours = 8))
but I found that, when creating it many times, the length of them are not the same,
do you know how to fix it ?
a
andylamax
12/17/2023, 2:11 AM
you can pad it with trailing zeros. Thats why the lengths aren't the same
k
kurt_steiner
12/17/2023, 9:14 AM
can you show me how ?
a
andylamax
12/17/2023, 10:08 AM
Just to be clear, you need the string representation to have equal length right?? just the representation
k
kurt_steiner
12/17/2023, 10:09 AM
they are not string, they are column of timestamp in postgresql
a
andylamax
12/17/2023, 1:40 PM
If its not the representation thats a problem, then why is the length a concern? becoz in the end, padded with zeros or not, the value will be the same altogether
i.e.
2023-12-16 21:51:29.544
is the same as
2023-12-16 21:51:29.544000
k
kurt_steiner
12/17/2023, 1:41 PM
thank you for focus still, I have fix it with this code
Copy code
val date = ZonedDateTime.parse(isostring).toInstant()
val result = formatDateFormat.format(date.atZone(ZoneOffset.UTC))