MriX
(Maximilian)
August 18, 2017, 7:35pm
1
I would like to format the state of a DateTime item. This error date should be sent via email.
Can I change the format of the DateTime item to: “18.08.2017 20:20”?
Item:
DateTime ErrorDate "Error date [%1$td.%1$tm %1$tH:%1$tM]" {channel="binding:name:name:error#date"}
Rule:
sendMail("test@test.com", "Error", "\nError Date: " + ErrorDate.state)
Received email:
Error Date: 2017-08-18T20:20:48.000+0200
1 Like
I’m not sure if there is an easier way, but what I do in my rules could look similar to this for your use case
Rule:
var DateTime error = parse(""+ErrorDate.state)
sendMail("test@test.com", "Error", "\nError Date: " + error.toString("dd.MM.yyyy HH:mm"))
namraccr
(namraccr)
August 18, 2017, 10:52pm
3
Something like this should work, in theory, if you replace the format markers appropriately:
var String tmp = ErrorDate.state.format("%1$td.%1$tm %1$tH:%1$tM")
Found in this thread .
2 Likes
MriX
(Maximilian)
August 19, 2017, 8:38am
4
Thanks for the tips.
So I solved it like @namraccr suggested it:
sendMail("test@test.com", "\nError Date: " + ErrorDate.state.format("%1$td.%1$tm.%1$ty %1$tH:%1$tM"))
1 Like