4

Code:

    var date = new Date().toLocaleTimeString({timezone: 'UTC'});

The result is 4 hours difference from the real current time. Could someone help?

  • Is it client or server side? When I run this code in browser's console it shows correct time for me. By the way, what you are trying to do? – Pavel Shkleinik Aug 07 '17 at 23:49
  • 1
    Note: Dates created by client scripts use the default browser timezone, while dates created by server scripts use getScriptTimeZone(), which returns the script creator's timezone. – Wilmar Aug 07 '17 at 23:57
  • Thanks a lot for your messages Pavel and Wilmar. – Meriton Gjymshiti Aug 08 '17 at 10:39
  • Hi Wilmar, I tried now the same code in the client script and it works fine now. Thanks a lot. Before, I wrote the code in the server scripts, that's why it was showing incorrect time. – Meriton Gjymshiti Aug 08 '17 at 10:40

2 Answers2

5

I suppose the 4 hours difference is because you are using UTC. If that is so, then please make sure to use the correct time zone. For example:

new Date().toLocaleString('en-US', { timeZone: 'America/New_York', hour12: true });

For a list or the complete time zone values you can consult here. I hope it helps!

Morfinismo
  • 4,985
  • 4
  • 19
  • 36
1

In the App settings, Have you set your Time zone? Perhaps this is the issue. In the client side, it will use the client time, on the server side, it will use Server time. Hope this helps!