Scala - 处理时间(nscala-time - Joda Time的scala封装)

GITHUB : https://github.com/nscala-time/nscala-time

MAVEN : (注意选对scala版本)

<dependency>
<groupId>com.github.nscala-time</groupId>
<artifactId>nscala-time_2.10</artifactId>
<version>2.6.0</version>
</dependency>

代码示例:

记得 import com.github.nscala_time.time.Imports._

scala> DateTime.parse("20150101", DateTimeFormat .forPattern("yyyyMMdd"))
res11: org.joda.time.DateTime = 2015-01-01T00:00:00.000+08:00

scala> DateTime.parse("2015-01-01")
res12: org.joda.time.DateTime = 2015-01-01T00:00:00.000+08:00

scala> DateTime.parse("2015-01-01T08:23:56")
res13: org.joda.time.DateTime = 2015-01-01T08:23:56.000+08:00

scala> DateTime.now + 2.months
res14: org.joda.time.DateTime = 2016-03-20T17:46:31.288+08:00

scala> DateTime.nextMonth < DateTime.now + 2.month
res15: Boolean = true

scala> DateTime.now to DateTime.tomorrow
res16: org.joda.time.Interval = 2016-01-20T17:46:31.743+08:00/2016-01-21T17:46:31.743+08:00

scala> (DateTime.now to DateTime.nextSecond).millis
res17: Long = 1000

scala> 2.hours + 45.minutes + 10.seconds
res18: com.github.nscala_time.time.DurationBuilder = com.github.nscala_time.time.DurationBuilder@90c70e54

scala> (2.hours + 45.minutes + 10.seconds).millis
res19: Long = 9910000

scala> 2.months + 3.days
res20: org.joda.time.Period = P2M3D

scala> DateTime.now.hour(2).minute(45).second(10)
res21: org.joda.time.DateTime = 2016-01-20T02:45:10.762+08:00

上一篇:类之string类、Math类、DateTime类


下一篇:CSS如何让DIV的宽度随内容的变化