Skip to content
Advertisement

How to print times (hh:mm) in a quarter-hour cycle?

I need to basically print every quarter-hour of the day from 00:00 to 23:45 (so 96 different times) in hh:mm format to create a html report. Is there a standard library to do that? Or another way?

JavaScript

Advertisement

Answer

Can be done using the java.time.LocalTime:

JavaScript

It can also be done with a for loop, just consider that LocalTime does not accept 24:00, so 23:45 + 0:15 results in 00:00.


The default format used by LocalTime.toString() is HH:MM if seconds and fraction of seconds is zero. A DateTimeFormat can be used to format the tine using a different format.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement