字符串转日期
import java
.text
.SimpleDateFormat
import java
.time
.{LocalDate
, LocalDateTime
}
import java
.time
.format
.DateTimeFormatter
object date
{
def main
(args
: Array
[String]): Unit = {
val date
= LocalDateTime
.parse
("2017-01-01 13:14:59",DateTimeFormatter
.ofPattern
("yyyy-MM-dd HH:mm:ss"))
println
(date
)
println
("="*50)
val date1
= LocalDate
.parse
("2018-10-18",DateTimeFormatter
.ofPattern
("yyyy-MM-dd"))
val year
= date1
.getYear
val month
= date1
.getMonth
.getValue
val week
= date1
.getDayOfMonth
println
("年:"+year
+" 月:"+month
+" 日:"+week
)
println
(date1
)
println
("="*50)
val date2
= new SimpleDateFormat
("yyyy-MM-dd HH:mm:ss").parse
("2020-10-22 10:13:36")
println
(date2
)
println
("="*50)
val date3
= date2
.getTime
println
(date3
)
}
}
执行结果:
2017-01-01T13
:14:59
==================================================
年:
2018 月
:10 日
:18
2018-10-18
==================================================
Thu Oct
22 10:13:36 CST
2020
==================================================
1603332816000
转载请注明原文地址: https://lol.8miu.com/read-27952.html