NTP Binding - Formatting DateTime

Hello,

I’m using openHAB 2.4 and looking at the NTP binding documentation here:

My things and items are defined per the documentation and listed below.

ntp.things

ntp:ntp:demo  [ hostname="us.pool.ntp.org", refreshInterval=60, refreshNtp=30 ]

ntp.items

DateTime Date  "Date [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]"  { channel="ntp:ntp:demo:dateTime" }

Am I missing something or should the Java documentation for formatting link point to:

https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html

Right now it doesn’t seem appropriate as it it points following which doesn’t seem to work for me.

https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

Regards,
Burzin

That link results in a 404 error.

The second one (SimpleDateFormat (Java Platform SE 6)) is correct.

Oops poor copy and paste.

https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html

The above should work. My point is this the following table doesn’t produce usable results-- at least for me. Before updating the wiki, I’d like a sanity check. Perhaps my installation is wack somehow.

Regard,s
Burzin

You’ll need to define what you mean by “doesn’t work”. Maybe include the actual result that you’re thinking is wrong…

Hi,

I want my sitemap to display the date and time like this:

image
This configuration gets me there

default.sitemap

sitemap default label="My Home" {
    Frame label="Current Date and Time" {
        Text item=Date
    }
}

ntp.things

ntp:ntp:demo  [ hostname="us.pool.ntp.org", refreshInterval=60, refreshNtp=30 ]

ntp.items

DateTime Date   "[%1$tA, %1$tB %1$td, %1$tY — %1$tl:%1$tM %1$tp]"  { channel="ntp:ntp:demo:dateTime" }

However, if I follow [https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html,

ntp.items looks like this:

DateTime Date   "[%1$tE, %1$tM %1$td, %1$ty — %1$th:%1$tm %1$ta]"  { channel="ntp:ntp:demo:dateTime" }

Translated that should equate to:

`E` Day in week [Text] - Example `Saturday` ;  `Sat` 
`M` Month in year [Month] - Example `January` ;  `Jan` ;  `01`
`d` Day in month [Number] - Example `5`
`y` Year [Year] - Example '2019` ;  `19`
—
`h` Hour in am/pm (1-12) [Number]- Example '8`
`m` Minute in hour [Number] - Example `05`
`a` Am/pm marker [Text] - Example  `PM`

Instead of the desired output, I get this:

image

Regards,
Burzin

You’re right, that’s a defect in the README. The original OH1 README correctly points to the Formatter class instead of the SimpleDateFormat class.

Hi,

I created an update request at: https://github.com/eclipse/smarthome/pull/6807

Regards,
Burzin