1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 23:58:01 +00:00

Add Get The Time Zone Of The Client Computer as a javascript til

This commit is contained in:
jbranchaud
2018-10-18 13:42:15 -05:00
parent e9bf8b1619
commit f829077e02
2 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
# Get The Time Zone Of The Client Computer
The
[`resolvedOptions`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
function on `Intl.DateTimeFormat.prototype` provides a number of pieces of
information about the client computer. It includes information such as the
locale and the numbering system. It also has the time zone for that machine.
Try running this line of JavaScript in your own browser.
```javascript
$ Intl.DateTimeFormat().resolvedOptions().timeZone
```
When I run it, I get `America/Chicago`.
You can use this within your client-side code as a way of determining in
which time zone your users are.