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. 10个强大的Apache开源模块

    1.单点登录模块 LemonLDAP LemonLdap可以很棒地实现Apache的SSO功能,并且可以处理超过 20 万的用户请求.LemonLdap支持Java, PHP, .Net, Perl, ...

  2. Script.NET Perl解释器代码已经在GitHub开源发布

    Script.NET Perl解释器的代码已经提交到GitHub网站.GitHub项目地址: https://github.com/blueantst/Script.NET Perl解释器代码在Src ...

  3. php中的$_SERVER从哪来

    前几个月学了个tcpdump抓包命令,遇到任何问题总想试试,真是程序员的终级武器呀,它像显微镜一下,把任何的丑陋的bug都显示在你的面前. 为什么有题目中所说的疑问呢?因为我发现在不同的环境下面,我获 ...

  4. 编程实例--for循环,找出0~100之间与8有关的正整数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 【转】C++中继承中的同名成员问题

    C++中,子类若有与父类同名的成员变量和成员函数,则同名的成员变量相互独立,但同名的子类成员函数重载父类的同名成员函数.举例如下: #include <iostream> using na ...

  6. 微软正式提供Visual Studio 2013正式版下载(附直接链接汇总)

    转自 http://www.iruanmi.com/visual-studio-2013/ 微软已经向MSDN订阅用户提供了Visual Studio 2013正式版镜像下载,只是非MSDN用户能够在 ...

  7. Android 颜色渲染(六) RadialGradient 环形渲染

    Android 颜色处理(六) RadialGradient 环形渲染 public RadialGradient(float x, float y, float radius, int[] colo ...

  8. android开发入门经验 ADT Bundle环境搭建

    现在有许多做开发的转做移动端开发,做J2EE的转做Android开发,我也把自己的一些入门经验与大家分享一下,希望能给你带来帮助. 工具/原料 JDK,ADT,JAVA 方法/步骤   开发工具的准备 ...

  9. gallery左右滑动时图片淡入淡出

    前几天,公司项目有一个功能要做成滑动图片的淡入淡出,要一边滑动一边改变,所以ViewFlipper左右滑动效果就不能了.网上找了很久,也找不到资料,所以自己写了一个,通过滑动改变imageView的透 ...

  10. 【转】GitHub平台最火的iOS开源项目——2013-08-25 17

    http://www.cnblogs.com/lhming/category/391396.html 今天,我们将介绍20个在GitHub上非常受开发者欢迎的iOS开源项目,你准备好了吗? 1. AF ...