Get Time Period on System Start Failing due to getCalendar()

I have the same problem of depreciated, and tried the toEpochSecond suggestion above, which errored and didn’t work.(I’m using OH 2.2 release version).

The depreciated line is the first one, and the second (commented out) is what i tried but was wrong. Can anyone please tell me what I need to use instead? Thanks.

		var DateTime LastTagged = new DateTime((iTagDateTime.state as DateTimeType).calendar.timeInMillis)
//		var DateTime LastTagged = new DateTime((iTagDateTime.state as DateTimeType).toEpochSecond * 1000)

Check the link right above your post.

var DateTime LastTagged = new DateTime((iTagDateTime.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
1 Like

I have it this way:

old:
val lastMillis = (lastTime.state as DateTimeType).calendar.timeInMillis

new:
val lastMillis = (lastTime.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli

I think you forgot the “get” in “getZonedDateTime”? Or is both working?

thank you 5iver, that worked.

I still have the following few lines of code I need to convert too, if anyone could please say? Thanks.

	val calendar = java.util.Calendar::getInstance
	calendar.timeInMillis = now.millis
	val dtt = new DateTimeType(calendar)

I don´t know what you want to say to me with this???

Is getZonedDateTime also depricated?

Or is it right / wrong? Or are both versions working?

Sorry… this shows that getZonedDateTime is actually derived from zonedDateTime. But they both will work and are equivalent.

1 Like

It looks like you are getting the current time as DateTime, probably to compare to a DateTime item. Try this…

val DateTime dtt = new DateTimeType(now.toString)

hi 5iver,

thanks. It gets used to postUpdate to a datetime item.

This is another area that I’m not the biggest fan of the Xtend language. The short of it is you do not have to provide the “get” part of a call to any method that starts with “get”.

val DateTime dtt = new DateTimeType()

is sufficient. With no parameters it defaults to now.

1 Like