Can someone clarify what format the timestamp returned by the .lastUpdate extension? I have the following rule working well to check for communication failures, but I cannot figure out how to format this date for display. (Using mysql for persistence)
rule "Item Comm Failure"
when
Time cron "0 0 8 1/1 * ? *" //Once Daily at 8:00 AM
then
if (!<item>.updatedSince(now.minusSeconds(90))) {
logInfo("ItemCommFailure", "Item Failure. Time of last update is: " + <item>.lastUpdate)
sendTweet("Item Comm Failure. Time of last update is: " + <item>.lastUpdate)
}
end
The string looks to be in the same format as yours.
2017-01-06 13:00:00.109 [INFO ] [se.smarthome.model.script.Irrigation] - Frontyard Irrigation Controller Comm Failure. Time of last update is: 2017-01-05T21:26:40.000-06:00
Sorry, I guess I wasn’t clear about what I’m trying to do. I want to be able to change the display format of this timestamp, I’d like to send and email or tweet that has a time stamp that is easier for a “normal” person to read. (eg. Last update was Friday January 6, 2017 at 01:20 pm).
I’ve got this figured out now. It seems that the missing link is to use .toDate.toString()
var String Timestamp = myItem.lastUpdate.toDateTime.toString("EEE MMM dd, yyyy hh:mm:ss a")
if (!FrontyardIPaddress.updatedSince(now.minusSeconds(90))) {
logInfo("myItem", "Item Comm Failure. Time of last update is: " + Timestamp)
}
Gives me:
- Item Comm Failure. Time of last update is: Thu Jan 05, 2017 09:26:40 PM
I’m not sure if this is the best way, If there is a better way I’d love to hear it.