Current time with daylight saving applied

I need current date and time as string.
Tried this:

		def dateTime = new Date()
		def sensorStateChangedDate = dateTime.format("yyyy-MM-dd HH:mm:ss")

The problem is that time is one hour less than current time, I think because daylight saving is not applied.

How can I get correct time?

You need to specify your time zone (otherwise the date/time will be in UTC):

def sensorStateChangedDate = dateTime.format("yyyy-MM-dd HH:mm:ss", location.timeZone)
1 Like

Thank you @ahndee, this fixed my issue.

Weird that SmartThings support didn’t know this, their best answer was to ask the community.