hey, I have a method that get the time of shanghai...
# kotlinx-datetime
k
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
you can pad it with trailing zeros. Thats why the lengths aren't the same
k
can you show me how ?
a
Just to be clear, you need the string representation to have equal length right?? just the representation
k
they are not string, they are column of timestamp in postgresql
a
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
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))