1.把输入字符串时间转换为时间戳

    val str="2020-06-01 14:21:42"
    val format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val timeStamp: Long = format.parse(str).getTime //这里获取到的时间精确到毫秒级别
    println(timeStamp.toString) // 1590992502000

 

2.获取到当前系统的时间戳

 println(System.currentTimeMillis()) //单位到毫秒

 

3.获取到当前系统的时间

 println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date))

 

相关文章:

  • 2021-06-27
  • 2022-02-21
  • 2022-12-23
  • 2022-02-04
  • 2021-12-05
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-09-08
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案