Sabre66
(T Dods)
May 16, 2017, 6:19pm
1
Hi, i have the NTP binding, and simply trying to get 12 hour time with am/pm.
This is my .item line right now
DateTime Date “[%1$ta, %1$te %1$tb %1$tY, %1$tl:%1$tM %1$tp]” { channel=“ntp:ntp:datetime:dateTime” }
But, the time comes back as '2PM:16 PM"
Everything i read say “l” (lower case L) is supposed to just be 12 hour number, but it keeps putting a PM on it. same if i use “I” (cap eye). Thanks
vegarroe
(Vegar Røyset)
May 16, 2017, 7:44pm
2
In my config I do not get AM PM when using l (lower case L) or I (upper case eye). The difference is leading zero for hours 0 - 9.
Formatting overview here:
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
Is your locale settings correct? ref:
‘r’ Time formatted for the 12-hour clock as “%tI:%tM:%tS %Tp”. The location of the morning or afternoon marker (’%Tp’) may be locale-dependent.
Try to replace
DateTime Date "[%1$ta, %1$te %1$tb %1$tY, %1$tl:%1$tM %1$tp]" { channel="ntp:ntp:datetime:dateTime" }
With
DateTime Date "[%1$ta, %1$te %1$tb %1$tY, %1$tr]" { channel="ntp:ntp:datetime:dateTime" }
You will get the seconds in the time part!
Sabre66
(T Dods)
May 16, 2017, 7:48pm
3
Thank you! That does work, gets rid of the extra AM/PM after the hour. Do you know how i would get rid of the seconds w/ using the ‘r’ parameter? And cut reduce to single digit for the hour if it does not need it?
vegarroe
(Vegar Røyset)
May 16, 2017, 7:52pm
4
The r parameter is predefined so I don´t think you can change it, but your original setup works for me:
DateTime Luftfuktighet_Bad2_LUpdate "Fukt bad 2. etg oppdatert [%1$ta, %1$te %1$tb %1$tY, %1$tl:%1$tM %1$tp ]" <clock> (Temperatur_2, TempUpd)
I’m having the same issue of times appearing like 5 PM:30 PM. It seems to be a locale issue but I’ve confirmed all my locale settings are set to English/United States.
It might be a formatting issue but I cannot see your formatting or OH version from here.
I’m on openHAB 2.4.0 Release build. The time formatting I’m using is:
[%1$tl:%1$tM %1$Tp]
Just looking quickly, I found this:
===
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.
1 Like
Eric_P
(Eric)
August 25, 2019, 6:33pm
10
Hi, I’m trying to format the time with the following item:
DateTime Time “Time [%1$tI:%1$tM %1$Tp]”
But I get this on PaperUI:
01 PM:31 PM
I don’t know where is that extra PM coming from.
Other formats work properly.
Thanks!
rossko57
(Rossko57)
August 25, 2019, 7:32pm
11
I format mine like this [%1$tr]
sunset_time "Sunset [%1$tr]" <sunset> {channel="astro:sun:local:set#start"}
1 Like