A scala package which a wrapper for Joda Time base on scala-time

Installation

SBT

1
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "2.16.0"

Import

1
import com.github.nscala_time.time.Imports._

Construction

1
2
val dt = new DateTime();
val now = Datetime.now

TimeZones

1
val zone = DateTimeZone.forID("Europe/London");

Date fields

1
2
3
4
5
6
7
8
9
10
11
dt.getEra();
dt.getYear();
dt.getWeekyear();
dt.getCenturyOfEra();
dt.getYearOfEra();
dt.getYearOfCentury();
dt.getMonthOfYear();
dt.getWeekOfWeekyear();
dt.getDayOfYear();
dt.getDayOfMonth();
dt.getDayOfWeek();

Formating

pattern letters

In

Build formater

1
val fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")

Generate DateTime

1
val dt = Datetime.parse("2013-02-02 02:11:13", fmt)

Or

1
val dt = fmt.parseDateTime("2013-02-02 02:11:13")

Out

1
dt.toString("yy-MM-dd")