[英]How to parse a datetime string without a year in Joda Time?
我需要將字符串轉換為Joda Time DateTime
值。 字符串表示形式包含日,月,小時和分鍾,但不包含年份。
我該怎么做?
我嘗試了類似DateTimeFormat.forPattern("dd.MM HH:mm").parseDateTime("26.03 02:50")
,但遇到以下異常:
org.joda.time.IllegalInstantException: Cannot parse "26.03 02:50": Illegal instant due to time zone offset transition (Europe/Moscow)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:471)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:440)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:411)
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:882)
您接近它……例如,使用parseLocalDateTime函數:
DateTimeFormat.forPattern("dd.MM HH:mm").parseLocalDateTime("26.03 02:50");
但是請注意,此解決方案會忽略任何可能給出的時區信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.