mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Start Node Process In Specific Timezone as a javascript til
This commit is contained in:
35
javascript/start-node-process-in-specific-timezone.md
Normal file
35
javascript/start-node-process-in-specific-timezone.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Start Node Process In Specific Timezone
|
||||
|
||||
When running a node process on your machine locally, it will adopt your
|
||||
machine's local timezone.
|
||||
|
||||
I can observe this by starting a `node` process and outputting a date with
|
||||
`toLocaleString()`.
|
||||
|
||||
```javascript
|
||||
> new Date().toLocaleString()
|
||||
'11/30/2020, 8:48:17 PM'
|
||||
```
|
||||
|
||||
This is the time that I'm writing this post, in Chicago (CST).
|
||||
|
||||
I can then start the process in another timezone, such as UTC.
|
||||
|
||||
```bash
|
||||
$ TZ=utc node
|
||||
```
|
||||
|
||||
With that `node` process, I can now do the same experiment.
|
||||
|
||||
```javascript
|
||||
> new Date().toLocaleString()
|
||||
'12/1/2020, 2:52:40 AM'
|
||||
```
|
||||
|
||||
The time jumps ahead about 6 hours because it is going from CST (UTC-6) to UTC.
|
||||
|
||||
Similarly, I could start the Node process for the west coast like so,
|
||||
|
||||
```bash
|
||||
$ TZ='America/Los_Angeles' node
|
||||
```
|
||||
Reference in New Issue
Block a user