toDateTime() Throwing an error


(Ray Caruso) #1

Hello all,

New Guy here. I am trying to use toDateTime() per the on-line doc and cannot for the life of me figure out why it is throwing the following error:

error groovy.lang.MissingMethodException: No signature of method: script1498162028651327298618.toDateTime() is applicable for argument types: (java.lang.String) values: [2017-06-22T14:07:10.456-0600]

Any clues would be greatly appreciated.
Code follows

Thank You in advance

Ray

definition(
    ....

preferences 
section("MyTime") {
        input "mytime", "time"
    }
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
	initialize()
}

def initialize() {
   Date myTimeAsDate = toDateTime(mytime) // This Throws... Why?
}

#2

Almost a year later and I was having the same issue. I figured out that toDateTime now requires passing an additional parameter with the timezone. It works fine with:
Date myTimeAsDate = toDateTime(mytime, location.timeZone)

Hope that helps you as it does me.