Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的一个 Scala 2.8 程序中,我使用 joda-time 及其 scala-time 包装器。我有 2 个 DateTime 值,一个用于日期(时间字段为零),一个用于时间(日期字段为零)(分离的原因是存储架构)。
如何从源对中同时设置日期和时间部分来获取另一个 DateTime 值?
您应该使用LocalDate日期和LocalTime时间。这些分别是日期和时间的适当类型。您可以从DateTimewith中获取每个DateTime.toLocalDate(),DateTime.toLocalTime()如果您必须将它们作为DateTime值开始。DateTime理想情况下,在您分别获得两个位之前,您根本不会构建 a :)
LocalDate
LocalTime
DateTime
DateTime.toLocalDate()
DateTime.toLocalTime()
然后就可以了LocalDate.toDateTime(LocalTime, DateTimeZone)。
LocalDate.toDateTime(LocalTime, DateTimeZone)