Skip to content
何も考えずにJoda-Time (Java, Scala)
java-tips-scala-tips
software
2019-09-19

sdt.

libraryDependencies += "joda-time" % "joda-time" % "2.9.9"

meven

<dependency>
  <groupId>joda-time</groupId>
  <artifactId>joda-time</artifactId>
  <version>2.9.9</version>
</dependency>

今または指定日時

val date = DateTime.now()
val date = new Date(2001,1,1,12,30,0)

足す、引く

val date = date.plusDays(1)
val date = date.minusYear(1)

書く

val str = date.toString()
val str = date.toString("yyyy/MM/dd HH:mm:ss")
//エスケープは ' で囲む 
val str = date.toString("yyyy-MM-dd'T'HH:mm:ss")
val date = DateTime.parse(str,DateTimeFormat.forPattern("yyyyMMdd"))