Converting local time to UTC time


(Todd Wackford) #1

I have an app that calculates a local time into this format:

“17:15”

I need to get the offset to UTC time and format it to send thru the API for scheduling an event.

Any ideas how to do this?


(Bob Florian) #2

Hi Todd,

We currently don’t have the local time zone offset.  That is something we’re working on.  Is this for the NST app? Is there any way you can get the offset from the source of your sunrise/sunset times?


(Todd Wackford) #3

Hey Bob,

I figured out a workaround for now (temporary) and yes it is for the NST App. As for your last question, that was my original question. “What is the offset to UTC and then format it to schedule a time”.

The IDE only accepts (at least from my short experience) UTC times. If you create a variable “def  myTime = new Day()” it gives you the current date and time in regards to UTC time. So what I have done is something like this:

Get sunrise or sunset time
Get current local time using zip code (Works in most of US, but not all)
Get current UTC time
Calc offset value
Apply offset to sunrise and sunset times
Schedule them

Dates and times are a pain the you-know-what in java and groovy. I’m going to make a myself a robust little library just for handling them.

I always forget how frustrating software can be and this little app reminded me. After getting everything working right (I thought) and putting it out to run, it did not work on the first day. Arggggg, WT(n=variable)! After looking over and over at my code, I finally realized that I was scheduling everything to start tomorrow in UTC time. My first sunrise did not turn off the lights. So I had to back up the SmartThings scheduler by subtracting a day. Weee fun.

This stuff is addicting…

Todd Wackford (Twack)