当使用Java.time将日期时间转换为epoch时,如何处理边缘情况



这是我的代码,它将日期-时间转换为epoch时间戳,有一种情况我不知道如何处理,如果时间戳中包含区域信息,并且没有将其作为此函数的第三个参数传递,则无论时间戳中的时区是什么,它都将始终转换为UTC,如何解决此问题?

time_to_epoch(List(JString("2007-12-03T10:15:30 CET"), JString("yyyy-MM-dd'T'HH:mm:ss z"))) shouldEqual JString("1196669730000")

time_to_epoch(列表(JString("2007-12-03T10:15:30+02:00"(,JStringtime_to_epoch(列表(JString("2007-12-03T10:15:30 CEST"(,JString

whatever timezone in the timestamp, the result is wrong, i.e, CEST(+02:00), output (+01:00), America/Mexico_City(+05:00), output (+04:00)

如果时区数据可以是timestamp字符串的一部分,那么无论是否默认提供,都应该让它覆盖timezone字符串。

formatter.parseBest(timestamp, ZonedDateTime.from _
, LocalDateTime.from _
, LocalDate.from _) match {
case zdt: ZonedDateTime =>
JString(zdt.toInstant().toEpochMilli.toString)
case ldt: LocalDateTime =>
. . .

最新更新