How to set timezone for web engine's javascript engine?
-
wrote on 9 Nov 2019, 01:41 last edited by
Current behavior
- Create a
QWebEngineView
- Visit https://codepen.io/pen/, open the console at the lower left corner
- Run
Date()
This would show the local system's local time and timezone.
Question
How can I tell
QWebEngineView
to use a different timezone when executing javascript in the browser, instead of using the system timezone? - Create a
-
Current behavior
- Create a
QWebEngineView
- Visit https://codepen.io/pen/, open the console at the lower left corner
- Run
Date()
This would show the local system's local time and timezone.
Question
How can I tell
QWebEngineView
to use a different timezone when executing javascript in the browser, instead of using the system timezone?wrote on 9 Nov 2019, 10:06 last edited by@Vinnie
So this is a generic question about JavaScript rather than anything to do specifically withQWebEngine
(Chromium). JS allows you to read the current timezone (of the browser) but not set it. You have to do the manipulations in code yourself on aDate
object to "emulate" a different tz. Have a read of, e.g. https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone. - Create a
1/2