Working with time zone

i have this code in a DH to present when device has been seen/expected. but it uses UTC i cant seam to figer how to get it to use the hub time zone?

def nowtime = now()
    def nowtimeplus = nowtime + (settings.wakeUpIntervalInMins * 60 * 1000)
    def nowtimeplusdate = new Date(nowtimeplus)

sendEvent(name: "lastseen" , value: "${new Date().format("dd-MM-yy HH:mm")} Next Expected ${nowtimeplusdate.format('HH:mm')}", displayed: false) //${settings.wakeUpIntervalI
1 Like

Try using:
nowtimeplusdate.format(‘HH:mm’,location.timeZone)

Here’s the reference for the Date class:
http://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Date.html

thats for that, unfortunatly the clocks have now changed here, it was tring to get this format ( the full) Mon Oct 28 08:12:16 UTC 2019 as aposed to just HH mm

8:07:16 AM: debug now = 1572250036064, plus = 1572250336064, Mon Oct 28 08:12:16 UTC 2019, 08:12

def nowtime =  now()
    def nowtimeplus = nowtime + (settings.wakeUpIntervalInMins * 60 * 1000)
    def nowtimeplusdate = new Date(nowtimeplus)


log.debug "now = $nowtime, plus = $nowtimeplus, $nowtimeplusdate, ${nowtimeplusdate.format('HH:mm',location.timeZone)}"

Your log line is printing nowtimeplusdate twice - first unformatted then formatted. This:

log.debug "$nowtimeplusdate"

will print Mon Oct 28 08:12:16 UTC 2019 while this:

log.debug "${nowtimeplusdate.format('HH:mm',location.timeZone)}"

will print 08:12.

i want Mon Oct 28 08:12:16 GMT 2019
cold do “d MM DD HH mm Z YYYY” just seams very long winded just to dispaly local as aposed to UTC

i dont understand how this does it with out all this (above)

That DTH has a method at the very end called formatDate. If you look through it, you’ll see that it’s doing the same thing, though even more long-winded.

thanks i skiped that bit because i thougth it was for battery events only. thanks again

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.