Skip to content

Instantly share code, notes, and snippets.

@HUGHNew
Created February 18, 2022 07:57
Show Gist options
  • Save HUGHNew/9ee417874722872a07abd711ceb9976b to your computer and use it in GitHub Desktop.
Save HUGHNew/9ee417874722872a07abd711ceb9976b to your computer and use it in GitHub Desktop.
time-relative functions in Kotlin/Java
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