Pat_M
March 20, 2023, 6:37pm
1
Hi!
I use BetterLogic (great app btw) to get $timenow$. It’s correct in Swedish time adjusted to DST.
I try <const d = new Date();> in Homey Script. It returns 1 hour wrong. I run that code in my browser (W3Schools Tryit Editor ) and it returns correctly.
How can I get Homey to return the correct time? This is vital for me.
Many thanks!
What does the humanTime say here?:
https://tools.developer.homey.app/tools/system
A way to force the right timezone is to temporary move your location to another timezone and move it back after a while
( …More > Settings > Location)
Or it is the issue Homey uses UTC everywhere.
Script (partly in dutch):
Probeer dit script eens:
return getCurrentTime("nl-NL","Europe/Amsterdam");
function getCurrentTime(locale, timezone){
let date = new Date();
return date.toLocaleString(locale,{timeZone: timezone });
//return date.toLocaleTimeString(locale,{timeZone: timezone });
//return date.toLocaleDateString(locale,{timeZone: timezone });
}
Ik heb het script nog even aangepast. Hij zal nu “datum+tijd” teruggeven, maar je kan ook alleen de tijd of alleen de datum ter…
2 Likes
Pat_M
March 21, 2023, 11:56am
3
Hi!
dateHuman
Tuesday 21st March 2023 12:54:00
dateDst
false
Both are correct “there” but not from the Homey Script console, where I need it. Weird! I will brush off my dutch now and read your thread!
Many thanks!
1 Like
Pat_M
March 21, 2023, 12:43pm
4
return getCurrentTime("nl-NL","Europe/Amsterdam");
function getCurrentTime(locale, timezone){
let date = new Date();
return date.toLocaleString(locale,{timeZone: timezone });
//return date.toLocaleTimeString(locale,{timeZone: timezone });
//return date.toLocaleDateString(locale,{timeZone: timezone });
}
Thank you, this worked!!!
3 Likes