Converting a Timer value

Hi Guys,

im using OH2 for a while now .
Now i am again at a point where i need help.
val String transdatetimePOWR2 = LastUpdatePOWR2.state.format("%1$td.%1$tm.%1$tY")
converts “2020-08-06T20:50:24.092+02:00” to this “2020-08-06” which works fine.

Now i am trying to convert a “now.createTimer” value “2020-08-06T20:50:24.092+02:00” instead of the “LastUpdatePOWR2” variable to a readable format “2020-08-06 20:50:24”.
When i use the same two lines and putting the now.createTimer value instead of the “LastUpdatePOWR2” i get the following error message: “Rule ‘Test Timer Set 1’: ‘format’ is not a member of ‘org.joda.time.DateTime’; line 8, column 49, length 52”

can anyone point me to the step where i can transform the now.createTimer value into a readable YMD HMS format please.

Thnx in advance

There is message somewhere in this forum to convert the time objects.
It explains also the difference between the time stamps (type).

Here it is: Date time conversion

1 Like

Hi, thnx. I read the post and am quite aware how to transform the values.
What i need is the right Syntax for using the
now.plusMinutes(minutes) value in a conversion rule like this:
val String transdatetimePOWR2 = LastUpdatePOWR2.state.format("%1$td.%1$tm.%1$tY")

Instead of the “LastUpdatePOWR2” i would like to use “now.plusMinutes(minutes)”.
i think “now.plusMinutes(minutes)” needs to be in brackets somehow, cause if you put it in just like it is OH2 throws an error with either state or format in it.
I tried several ways but havent found the right one yet.

Okay, but it’s not very clear to me what you want to accomplish.
What I read is that you want the item LastUpdateFromDateTimeTypePOWR2 represent a datetime value in YMD HMS, based on now plus X minutes, correct?
First of all type of item is LastUpdateFromDateTimeTypePOWR2. If it is a DateTime item, you can use the label to show the human readable view of the date.
To update such a item, you can use this:

LastUpdateFromDateTimeTypePOWR2.postUpdate(new DateTimeType(now.plusMinutes(X).toString)

Where X is the amount of minutes you need.

If your item is a string, then use this:

val transdatetimePOWR2 = now.plusMinutes(X).toString.format("%1$td.%1$tm.%1$tY")

Again where X is the amount of minutes you need.

Will this help you?

1 Like

i may have confused you with what i want to accomplish…


is a String item and the rule works fine with it. What i want is to use a


item and format it the way i do with the


I just cant figure out how to get the


item into the right output format.

From your input

val String MyStringFromJodaformatted = now.plusMinutes(minutes).toString.format("%1$td.%1$tm.%1$tY")

and this line:

logInfo(“Event logging”, "Starting timer for " + minutes + " minutes, ending at " + MyStringFromJodaformatted )

i get this output that is still not formatted correctly.

2020-08-08 12:10:08.029 [INFO ] [smarthome.model.script.Event logging] - Starting timer for 10 minutes, ending at 2020-08-08T12:20:08.019+02:00

I would like to have it like this: 2020-08-08 or with hours and minutes 2020-08-08 12:20

Dunno if i am sitting to long in front of the code so that i cant see the obvious…

var fred = now.plusMinutes(minutes)
 // this is a Joda datetime and not the same as Item datetime
 // Joda has built-in pattern style formatting
logInfo("test", "stuff " + fred.toString("yyyy-MM-dd' 'HH:mm"))

This is all referenced in the conversions link from @ljsquare

2020-08-08 11:54:37.271 [INFO ] [.eclipse.smarthome.model.script.test] - stuff 2020-08-08 13:24

ok. Thnx a lot. I knew it was something obvious… more brains and eyes are always better :slight_smile: