blob: 528f759fa2fa95c62ca9b33cfd0382090088fe0f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
---
name: Set a time zone in Bun
---
Bun supports programmatically setting a default time zone for the lifetime of the `bun` process. To do set, set the value of the `TZ` environment variable to a [valid timezone identifier](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
{% callout %}
When running a file with `bun`, the timezone defaults to your system's configured local time zone.
When running tests with `bun test`, the timezone is set to `UTC` to make tests more deterministic.
{% /callout %}
```ts
process.env.TZ = "America/New_York";
```
---
Alternatively, this can be set from the command line when running a Bun command.
```sh
$ TZ=America/New_York bun run dev
```
---
Once `TZ` is set, any `Date` instances will have that time zone. By default all dates use your system's configured time zone.
```ts
new Date().getHours(); // => 18
process.env.TZ = "America/New_York";
new Date().getHours(); // => 21
```
|