本文共 1322 字,大约阅读时间需要 4 分钟。
For processing dates, the Java Joda Time project is popular and well documented. A project named implements a Scala wrapper around Joda Time, and lets you write date expressions in a more Scala-like way, including these examples:
DateTime. now // returns org.joda.time.DateTimeDateTime. now + 2. monthsDateTime. nextMonth < DateTime. now + 2. months(2. hours + 45. minutes + 10. seconds). millis
com.github.nscala-time nscala-time_2.10 2.0.0
import com.github.nscala_time.time.Imports._object HelloWorld { def main(args: Array[String]) { println(DateTime.now + 2.months) // returns org.joda.time.DateTime = 2009-06-27T13:25:59.195-07:00 println(DateTime.nextMonth < DateTime.now + 2.months) // returns Boolean = true println(DateTime.now to DateTime.tomorrow) // return org.joda.time.Interval = > 2009-04-27T13:47:14.840/2009-04-28T13:47:14.840 println((DateTime.now to DateTime.nextSecond).millis) // returns Long = 1000 println((2.hours + 45.minutes + 10.seconds)) // returns com.github.nscala_time.time.DurationBuilder // (can be used as a Duration or as a Period) println((2.hours + 45.minutes + 10.seconds).millis) // returns Long = 9910000 println(2.months + 3.days) // returns Period }}
转载地址:http://wqouo.baihongyu.com/