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)
/**
* Xiaomi Aqara Temperature Humidity Sensor
* Version 1.3
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* Original device handler code by a4refillpad, adapted for use with Aqara model by bspranger
* Additional contributions to code by alecm, alixjg, bspranger, cscheiene, gn0st1c, foz333, jmagnuson, rinkek, ronvandegraaf, snalee, tmleafs, twonk, & veeceeoh
*
* Known issues:
* Xiaomi sensors do not seem to respond to refresh requests
* Inconsistent rendering of user interface text/graphics between iOS and Android devices - This is due to SmartThings, not this device handler
This file has been truncated. show original
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