Telegram messages sending NTP datetime

Very simply I am sending a message via telegram from within a rule. The code I have works fine, but I am struggling with one aspect. Within the message, I would like it to send the Date and Time that the notification was generated. e.g. Id like the message to read SOMETHING Changed to state X at 13:50 03-02-2018

if (SOMETHING.state == "BLAH" && MYBUTTON.state == ON) 	{ ITEMONSITEMAP.postUpdate("SOMETHINGHAPPENED") sendTelegram("TELEGRAMbot", "SOMETHING Changed to state X at DATE/TIME") }

Im really struggling to get the correct code for the DateTime aspect to work.

I have a DateTime Item thats bound to NTP, but if I use that to post its Status,

sendTelegram("TELEGRAMbot", "SOMETHING Changed to state X at DATE/TIME", Current_DateTime.state)

I get something in the format 2018-02-03T14:07:03.429+0000 … which is great… ish, but not exactly friendly to look at.

I know I need to setup this with something like [%1$tA, %1$td/%1$tm/%1$tY, %1$tH:%1$tM] though for the life of me, I cannot figure the correct structure, to get those settings/variables into my sendTelegram line within the rules.

Does anyone know how to do this, or perhaps have a simpler way of doing it?

Thanks

You could do it like this:

val String datetime_string  = Current_DateTime.state.format("%1$tA, %1$td/%1$tm/%1$tY, %1$tH:%1$tM")
sendTelegram("TELEGRAMbot", "SOMETHING Changed to state X at " + datetime_string)
1 Like

Thats absolutely perfect!

I tried something similar at one point, but didnt know about the .format being required pre the actual format.

V happy, thanks very much!