Peter
12/12/2023, 9:47 AMjava.time
(Android reasons). Any other robust alternatives?Filip Wiesner
12/12/2023, 9:49 AMPeter
12/12/2023, 9:50 AMFilip Wiesner
12/12/2023, 9:51 AMjava.time
is only since Java 11? You can desugar that to support earlier versions of AndroidPeter
12/12/2023, 9:52 AMFilip Wiesner
12/12/2023, 9:53 AMPeter
12/12/2023, 9:55 AMPeter
12/12/2023, 9:55 AMJacob Ras
12/12/2023, 11:01 AMeygraber
12/12/2023, 11:08 AMJacob Ras
12/12/2023, 11:08 AMPeter
12/12/2023, 11:24 AMPeter
12/12/2023, 11:25 AMMichael Paus
12/12/2023, 11:31 AMkotlinx-datetime
is multiplatform and even supports WASM. So, what is the problem with it? I am using it and did not have any problems so far.eygraber
12/12/2023, 12:34 PMRaed Ghazal
12/12/2023, 12:42 PMkotlinx-datetime
as well in an app that relies heavily on date time , but unfortunately as @eygraber said, it doesn’t have everything java.time has, but you can overcome this with a bit of extra code, I wrote an article about it, could be useful
Kotlinx DateTime manipulation for KMPMichael Paus
12/12/2023, 1:17 PMMichael Paus
12/12/2023, 2:05 PMactual fun parse(strDateTime: String)
doesn’t compile because it doesn’t specify a return type. I am also wondering why you are using Locale.ENGLISH
here instead of Locale.getDefault()
elsewhere.
Similar problem with format too.Raed Ghazal
12/12/2023, 9:12 PMRaed Ghazal
12/15/2023, 6:25 AMMichael Paus
12/15/2023, 8:58 AMfun LocalDateTime.Companion.now(timeZone: TimeZone = TimeZone.currentSystemDefault()): LocalDateTime
Sometimes you just want the current time in your default time zone but sometimes you also want to know the current time in some other time zone. For me it is most often the Zulu time that I am interested in too. Providing default arguments for all now() methods solves that problem.Raed Ghazal
12/15/2023, 9:06 AMfun parse(strDateTime: String): LocalDateTime
while in my application I have those 3 functions
fun parseToLocalDateTime(str: String): LocalDateTime
fun parseToLocalDate(str: String): LocalDate
fun parseToLocalTime(str: String): LocalTime
Raed Ghazal
12/15/2023, 9:08 AMMichael Paus
12/15/2023, 9:11 AMRaed Ghazal
12/15/2023, 10:17 AMRaed Ghazal
01/06/2024, 11:25 AMMichael Paus
01/06/2024, 12:01 PMRaed Ghazal
01/06/2024, 12:05 PMMichael Paus
01/06/2024, 12:07 PMMichael Paus
01/06/2024, 12:13 PMinstantBetween
not rather be durationBetween
?Raed Ghazal
01/06/2024, 1:52 PMRaed Ghazal
01/06/2024, 1:54 PMfun LocalDateTime.durationTo(
end: LocalDateTime,
timeZone: TimeZone = TimeZone.currentSystemDefault()
): Duration {
val start = this
if (end < start) throw IllegalArgumentException("end must be greater than start")
return end.toInstant(timeZone) - start.toInstant(timeZone)
}
Jacob Ras
01/06/2024, 2:11 PMdurationUntil
?Raed Ghazal
01/06/2024, 2:13 PMeygraber
01/06/2024, 11:36 PMRaed Ghazal
01/07/2024, 9:19 AM