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

Scala - 处理时间(nscala-time - Joda Time的scala封装)的更多相关文章

  1. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  2. Beginning Scala study note(3) Object Orientation in Scala

    1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...

  3. Beginning Scala study note(1) Geting Started with Scala

    1. Scala is a contraction of "scalable" and "language". It's a fusion of objecte ...

  4. Scala 深入浅出实战经典 第49课 Scala中Variance代码实战(协变)

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  5. 【Scala学习笔记】第01弹——Scala安装与配置

    安装Scala之前先要安装JDK(1.5以上),最好安装JDK 1.8+,安装好JDK后配置JDK的环境变量. 然后去Scala官网(http://www.scala-lang.org/downloa ...

  6. Scala入门(1)Linux下Scala(2.12.1)安装

    Scala入门(1)Linux下Scala(2.12.1)安装 一.文件准备 1.1 文件名称 scala-2.12.1.tgz 1.2 下载地址 http://www.scala-lang.org/ ...

  7. Scala学习之路 (七)Scala的柯里化及其应用

    一.概念 柯里化(currying, 以逻辑学家Haskell Brooks Curry的名字命名)指的是将原来接受两个参数的函数变成新的接受一个参数的函数的过程.新的函数返回一个以原有第二个参数作为 ...

  8. Scala学习之路 (四)Scala的数组、映射、元组、集合

    一.数组 1.定长数组和变长数组 import scala.collection.mutable.ArrayBuffer object TestScala { def main(args: Array ...

  9. Scala学习之路 (三)Scala的基本使用

    一.Scala概述 scala是一门多范式编程语言,集成了面向对象编程和函数式编程等多种特性.scala运行在虚拟机上,并兼容现有的Java程序.Scala源代码被编译成java字节码,所以运行在JV ...

随机推荐

  1. 抽象类Abstract的简单使用

    写了一个比较简单易懂的例子,如下图 AbstractBaseClass是抽象的基类,Class1,Class2是继承他的子类,并实现他的方法. //AbstractBaseClass.cs里的代码 p ...

  2. android ORMlite的应用

    ORMLite -轻量级的对象关系映射(ORM) 如果你需要在android中使用ORMLite 你需要进入官方网站http://ormlite.com/ 中下载 下载了这两个包以后,你还需要在对应的 ...

  3. 一秒钟速算(WINFORM)

    WIN7以上的系统可以直接运行,XP的系统要按装.NET 2.0 程序下载 http://files.cnblogs.com/xe2011/%E4%B8%80%E7%A7%92%E9%92%9F%E5 ...

  4. java中synchronized使用方法

    synchronized的一个简单样例 public class TextThread { /**  * @param args  */ public static void main(String[ ...

  5. 齐全的IP地址查询接口及调用方法(转)

    设计蜂巢IP地址查询接口:http://www.hujuntao.com/api/ip/ip.php 腾讯IP地址查询接口:http://fw.qq.com/ipaddress 新浪IP地址查询接口: ...

  6. 10465 - Homer Simpson 贪心

                                            Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Home ...

  7. netty Getting Started--reference

    reference from:http://docs.jboss.org/netty/3.1/guide/html/start.html 1.1. Before Getting Started 1.2 ...

  8. 【Android】 onSaveInstanceState()恢复数据

    onSaveInstanceState()方法会携带一个 Bundle 类型的参数,Bundle 提供了一系列的方法用于保存数据,比如可以使用 putString()方法保存字符串,使用 putInt ...

  9. Xcode快捷键、小技巧与xib圆角设置

    快捷键: 1.StoryBoard技巧 当你想直接在view中选择自己想要的元素时,但是又碍于一个view上叠加的元素太多很难直接选中,那么在这时,你同时按住键盘上的shift和 control键,然 ...

  10. [置顶] asp.net(c#)中相对路径(虚拟路径)和物理磁盘路径的转换

    物理路径就是磁盘路径,也就是说是在磁盘上的位置,虚拟路径也就是web页面上的路径,是相对于应用程序而言的 /// <summary> /// 将物理路径转换成相对路径 /// </s ...