0
的午夜秒我試圖用這樣的:的Java(喬達):從LocalDateTime
secondsFromMidnight = Seconds.secondsBetween(localDateTime.toLocalDate(),
localDateTime).getSeconds();
但它拋出一個異常(參見下文)。我認爲this是一個很好的方法,但我沒有成功地將它適用於我的案例。如果我寫這個:
DateTime dateTimeFromMidnight = new DateMidnight(localDateTime.getChronology()).toDateTime();
Duration duration = new Duration(dateTimeFromMidnight, localDateTime.toDateTime());
它隨着時區(我得到1小時)混亂。
如果您的解決方案也很容易適應小時,分鐘等,這是一個加號。
我絕對需要使用LocalDateTime作爲輸入類型,請不要用其他類發佈解決方案。
Exception in thread "main" java.lang.IllegalArgumentException: ReadablePartial objects must have the same set of fields
at org.joda.time.base.BaseSingleFieldPeriod.between(BaseSingleFieldPeriod.java:92)
at org.joda.time.Seconds.secondsBetween(Seconds.java:124)
什麼例外?你可以發佈嗎? – elyashiv