SmartThings Community

Adding time


(Mark C) #1

i want to add 5 minutes or variable (settings.wakeUpIntervalInMins)

def nowtime = new Date().time
def nowtimeplus = nowtime + (settings.wakeUpIntervalInMins * 60)
log.debug "now = $nowtime, plus = $nowtimeplus, "

i can get this debug now = 1548954627027, plus = 1548954627327,
but when i try to format it ${nowtimeplus.format(“dd-MM-yy HH:mm”)} i get an error
could some one advise


#2

Try this:

  def nowtime = now()
  def nowtimeplus = nowtime + (settings.wakeUpIntervalInMins * 60 * 1000)
  def nowtimeplusdate = new Date(nowtimeplus)
  log.debug "now = $nowtime, plus = $nowtimeplus, ${nowtimeplusdate.format('dd-MM-yy HH:mm',location.timeZone)}"

#3

Something like this could also work for you:

def myDate = new Date(now())
log.debug "Now = ${myDate.format('dd-MM-yy HH:mm',location.timeZone)}"
myDate.set(minute:myDate.minutes+5)
log.debug "Later = ${myDate.format('dd-MM-yy HH:mm',location.timeZone)}"

(Mark C) #4

worked thank you

def nowtime = now()
def nowtimeplus = nowtime + (settings.wakeUpIntervalInMins * 60 * 1000)
def nowtimeplusdate = new Date(nowtimeplus)
log.debug “now = nowtime, {now().format(“dd-MM-yy HH:mm”)} plus = nowtimeplus, {nowtimeplusdate.format(‘dd-MM-yy HH:mm’)}”