How to get the currect hour and minutes in Kotlin?

Hello Kotlin Community

I’ve recently tried to use the current time and minutes for a personal project. The issue is with the sintaxis from Programiz(Kotlin Program to Get Current Date/TIme), rather getting further than 12:00 it gets back to 1 o’clock.

What I want: 11:00;12:00;13:00;14:00;
What Kotlin saves: 11:00;12:00;1:00,2:00

Thanks in advance. And sorry for my bad English.

UPDATE: The problem was fixed thanks to user Eliote

Can you please just paste you code here, so that I can run it on my computer and find out what the problem is.
In addition, I think it’s probably something relating with Java but not Kotlin itself.


var time= currentDateTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)).removeSuffix(" AM").removeSuffix(" PM")


Take a look at DateTimeFormatter (Java Platform SE 8 )
You are getting the date formatted as you asked.
Try this:

var time = currentDateTime.format(DateTimeFormatter.ofPattern("HH:mm"))
1 Like

Thanks for the help.