Time and Date Formatting in openHAB

When you display Times and Dates in openHAB they are always in the format YYY-MM-DD and the 24-hour format. With a little bit of format rearranging in your ITEM file, you can format the Date and Time the way you want.

You can check here for the different ways to reformat the text to chance Time/Date displays.

For example, to display the Day of the Week, Month, Day, and the Year you would format the text like this in the ITEM file.

DateTime Date  "Date [%1$tA, %1$tB  %1$td, %1$tY]"

This will give you ex: Friday, March, 22, 2019 as shown on the Basic UI

If you wanted to display your Time in a 12-hour format with AM/PM notation then you would use this format

DateTime Time  "Time [%1$tI:%1$tM %1$Tp]"

This will give you ex: 12:21 PM as shown on the Basic UI

When formatting the text, as shown above, pay careful attention to the CASE of the letters.

In visiting the link above, you will see that the letter case makes a big difference in how the Time and Date are formatted. There is a section on Time/Date Conversions along with other numbers and string conversions.

I hope this helped you to format your Times and Dates on openHAB.

John Frankforther

11 Likes

Thanks for posting!
I insert a link to your post at DateTime Conversion.

1 Like