$jsapi.timeForZone
This method returns the current Unix time in the specified time zone.
Syntax
The method accepts one string argument: the time zone ID as per the Java specification. The method returns a number in milliseconds.
$jsapi.timeForZone("Europe/Berlin"); // => 1687505400000
tip
If your project uses
$jsapi.timeForZone
and has automated tests, you need to override the time the tests will treat as their current time.
Use the <dateTime>
tag to do this.How to use
# Here, we import the cities dictionary from the zb-common system project.
require: city/cityEn.sc
module = sys.zb-common
# Here we import the Moment.js library.
require: dateTime/moment.min.js
module = sys.zb-common
theme: /
state: CurrentLocalTime
q!: * (what time is it/what ('s/is) the time) * [in] $City *
script:
var timestamp = $jsapi.timeForZone($parseTree._City.timezone);
$temp.time = moment(timestamp).format("h.m a");
a: Right now, it’s {{$temp.time}} in {{$parseTree._City.name}}.