Created
February 18, 2022 07:57
-
-
Save HUGHNew/9ee417874722872a07abd711ceb9976b to your computer and use it in GitHub Desktop.
time-relative functions in Kotlin/Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.Instant | |
import java.time.LocalDate | |
import java.time.LocalDateTime | |
import java.time.LocalTime | |
import java.time.format.DateTimeFormatter | |
fun main(){ | |
print("local date: ${LocalDate.now()}") // 2022-02-18 | |
print("local time: ${LocalTime.now()}") // 15:46:05.838 | |
print("instant now: ${Instant.now()}"); // 2022-02-18T07:46:05.838Z | |
print("timestamp now: ${System.currentTimeMillis()/1000L}") // unix timestamp | |
print("format now: ${DateTimeFormatter.ofPattern("yy/M/dd|HH:mm:ss").format(LocalDateTime.now())}") // 22/2/18|15:46:05 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment