Advertisement
hivefans

timestamptodate.scala

Jun 4th, 2020
2,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.88 KB | None | 0 0
  1. package com.empgo
  2. import org.joda.time.{DateTime, DateTimeZone}
  3. import org.joda.time.format._
  4.  
  5.  
  6. object test {
  7.   def main(args: Array[String]): Unit = {
  8. //时间戳转时间  获取月 日
  9.     val tm = 1502036122000L
  10.     val dateTime = new DateTime(tm)
  11.     println(dateTime.getMonthOfYear +"=======" + dateTime.getDayOfMonth)
  12.     //获取时间字符串格式
  13.     val dateString = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").print(dateTime)
  14.     val datezoneString = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
  15.       .print(dateTime.withZone(DateTimeZone.UTC))
  16.  
  17.     println(dateString)
  18.     println(datezoneString)
  19.  
  20.     //ISO8601时间
  21.     val dt = ISODateTimeFormat.dateTimeNoMillis().print(dateTime)
  22.     //ISO8601 UTC
  23.     val dtzone = ISODateTimeFormat.dateTimeNoMillis().print(
  24.       dateTime.withZone(DateTimeZone.UTC))
  25.  
  26.     println(dt)
  27.     println(dtzone)
  28.   }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement