Computing local time from UTC time, and vice versa


(JJG) #1

I am in a different time zone from the SmartThings servers, and for the purpose of downloading multiple events since some past date (using “eventsSince(startDate,[max:1000])”), I need to do some arithmetic on “Dates”.
I found the UTC system time (“now Date()”) used for Events time stamping, and also my own location time zone (“location.timeZone”), but I cannot figure how to write a proper Java/Groovy code for my Smart App to derive UTC from local time and vice versa.

All my attempts failed miserably with various exotic return codes, which is not too surprising since I am definitely not a Java expert, and even less a Groovy one.

Also, I am not too sure about what to do with daylight saving times (“dstSavings”) : should I combine it with the time zone “offset” and if yes, how ? AFAIK, summer/winter time does not start the same day in all parts of the world (like the US vs Europe), and as a consequence actual time offsets between 2 different time zones may vary from one day to the next.

Any example of working code fully appreciated.