Get time from LocalDateTime
I'm looking to get the time from LocalDateTime (unless there is an easier way) with the format of HH:mm:a (12:34 pm) Which Date/Time formatter do I want to use?
val sdf = SimpleDateFormat("HH:mm:a")
val dt = LocalDateTime.now().format(sdf)
print("Time: $dt")
Solution 1:
I just managed to accomplish that the other way. Look at my code bellow.
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
fun main() {
val sdf = DateTimeFormatter.ofPattern("hh:mm:a")
val dt = LocalDateTime.now().format(sdf)
println("Time: $dt")
}
Reference:
Kotlin Program to Get Current Date/Time