赞
踩
- /*
- 时间戳
- */
-
- //获取当前时间戳
- timestamp() //1625209297
- timestamp().toDateString() //2021-07-02 13:54:29
-
- //获取当前天开始的时间戳
- LocalDateTime.of(LocalDate.now(),LocalTime.MIN).atZone(ZoneId.systemDefault()).toEpochSecond() //1625155200
- LocalDateTime.of(LocalDate.now(),LocalTime.MIN).toEpochSecond(ZoneOffset.of("+8")) //1625155200
-
-
- val timestamp = Instant.now()
- println("时间戳(秒): ${timestamp.epochSecond}")
- println("时间戳(毫秒): ${timestamp.toEpochMilli()}")
- println("时间戳(毫秒): ${System.currentTimeMillis()}")
- /*
- 时间和日期
- */
-
- //时间
- LocalTime.now() //13:57:02.187 .second .minute .hour
- //日期
- LocalDate.now() //2021-07-02 .month .year .dayOf年月周 可以加.value获取数字值
- //时间和日期
- LocalDateTime.now() //2021-07-02T13:58:22.179
-
- LocalDateTime.now(ZoneOffset.UTC) //UTC时间(世界标准时间):2021-07-02T05:59:37.435
-
- Instant.now() //2021-07-02T06:04:16.097Z
-
- DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now()) //2021-07-02
-
-
- ZonedDateTime.now() //2021-07-02T14:44:30.814+08:00[Asia/Shanghai]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。