hivefans

timestamptodate.scala

Jun 4th, 2020
1,216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×