【问题标题】:How to sum 2 joda-time DateTime values (one containing a date and a zero time and another containing a time and a zero date)?如何求和 2 个 joda-time DateTime 值(一个包含日期和零时间,另一个包含时间和零日期)?
【发布时间】:2010-09-08 23:14:47
【问题描述】:

在我的一个 Scala 2.8 程序中,我使用 joda-time 及其 scala-time 包装器。我有 2 个 DateTime 值,一个用于日期(时间字段为零),一个用于时间(日期字段为零)(分离的原因是存储架构)。

如何从源对中获取另一个同时设置日期和时间部分的 DateTime 值?

【问题讨论】:

    标签: java datetime scala jodatime


    【解决方案1】:

    您应该使用LocalDate 作为日期,使用LocalTime 作为时间。这些分别是日期和时间的适当类型。您可以从DateTimeDateTime.toLocalDate()DateTime.toLocalTime() 中获取每一个,如果您将它们作为DateTime 值开始。理想情况下,您根本不会构建DateTime,直到您分别获得这两个位:)

    那你可以LocalDate.toDateTime(LocalTime, DateTimeZone)

    【讨论】:

    • 我不想要本地时间。在这个项目中,我只使用严格的“Zulu”UTC。
    • @Ivan, LocalDate is an immutable datetime class representing a date without a time zone.
    • 它对我不起作用,我收到此错误:value toDateTime is not a member of scala.slick.lifted.Column[com.github.nscala_time.time.Imports.LocalDate]跨度>
    • @Anna:从表面上看,这不是在LocalDate 上调用toDateTime - 它是在尝试在Column[LocalDate] 上调用它......我不知道Scala,我不知道 nscal_time 包装器,但 toDateTime 肯定存在于 Joda Time 的 LocalDate 上。
    猜你喜欢
    • 2013-12-09
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多