λ°μν
Intro
μλ νμΈμ. μ΄λ²μκ°μλ μ½νλ¦°μμ νμ¬ λ μ§ λ° μκ°μ κ°μ Έμ€λ λ°©λ²μ λν΄ μμλ³΄κ² μ΅λλ€.
How to do
νμ¬ λ μ§, μκ°
νμ¬ λ μ§μ μκ°μ μλμ λ©μλλ₯Ό ν΅ν΄ κ°μ Έμ¬ μ μμ΅λλ€.
- LocalDateTime.now() : νμ¬ λ μ§μ μκ°
- LocalDate.now : νμ¬ λ μ§
import java.time.LocalDate
import java.time.LocalDateTime
fun main(args: Array<String>) {
val dateTime: LocalDateTime = LocalDateTime.now()
val date: LocalDate = LocalDate.now()
println("Current dateTime: $dateTime") // Current dateTime: 2023-01-12T22:54:32.505572
println("Current date: $date") // Current date: 2023-01-12
}
νΉμ λ μ§, μκ°
νμ¬ λ μ§κ° μλ νΉμ λ μ§λ₯Ό μμ±νκ³ μΆλ€λ©΄, λ€μκ³Ό κ°μ΄ of()λ₯Ό μ¬μ©νλ©΄ λ©λλ€.
import java.time.LocalDate
import java.time.LocalDateTime
fun main(args: Array<String>) {
val specificDate = LocalDate.of(2023, 2, 24)
val specificDate2 = LocalDateTime.of(2023, 11, 23, 10, 10, 10) // 2019λ
3μ 22μΌ 10μ 10λΆ 10μ΄
println("specificDate: $specificDate") // specificDate: 2023-02-24
println("specificDate2: $specificDate2") // specificDate2: 2023-11-23T10:10:10
}
λ°μν