/**
* 1:String 转LocalDate
* 1995-11-23
* */
val dateTimeFormate : DateTimeFormatter =DateTimeFormat.forPattern("yyyy-MM-dd")
val LocalDate = dateTimeFormate.parseLocalDate("1995-11-23")
println(LocalDate)
/**
* 2:String 转DateTime
* 1995-11-23T00:00:00.000+08:00
* */
val DateTime = dateTimeFormate.parseDateTime("1995-11-23")
println(DateTime)
/**
* 3:String转LocalDateTime
* 1995-11-23T00:00:00.000
* */
val LocalDateTime = dateTimeFormate.parseLocalDateTime("1995-11-23")
println(LocalDateTime)
/**
* 4:String转Date
*Thu Nov 23 00:00:00 CST 1995
* */
val dateFormat = new SimpleDateFormat("yyyy-MM-dd")
val StringToDate = dateFormat.parse("1995-11-23")
println(StringToDate)
/**
* 5:Date转String
* 1995-11-23
* */
val DateToString = dateFormat.format(StringToDate)
println(DateToString)
/**
* 6:Date转Long
* 1995-11-23
* */
val DateToLong = dateFormat.parse("1995-11-23").getTime
println(DateToLong)
/**
* 7:获取今天的日期(Date to String)
* 2019-12-16
* */
val now = new Date()
val today = dateFormat.format(now)
println(today)
/**
* 8:获取昨天的日期
* 2019-12-16
* */
val cal :Calendar = Calendar.getInstance()
cal.add(Calendar.DATE,-1)
val yesterday = dateFormat.format(cal.getTime)
println(yesterday)
scala 时间转化
最新推荐文章于 2024-09-19 11:08:14 发布