This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date-javascript.html
20 lines (20 loc) · 2.61 KB
/
date-javascript.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="description" content="Javascript Date objects have some weird intricacies that need attention."><!-- Bing --><meta name="msvalidate.01" content="45CBBE1BD8265A2217DFDA630EB8F84A" /><title>Tiny Brain Fans - Date (Javascript)</title><link rel="stylesheet" href="tinystyle.css"></head><body>
<main id="main"><article id="content"><h1 id="title">Date (Javascript)</h1><p><a href="javascript.html">Javascript</a> Date objects have some weird intricacies that need attention.</p>
<h2>Time Zones</h2>
<p>JavaScript's Date object tracks time in UTC internally, but typically accepts input and <strong>produces output in the local time of the computer it's running on</strong>. The way to mitigate this (IMO undesired) opinion is two options.</p>
<pre><code class="language-javascript">// will change time based on computer's time zone
var myBirthday = ('January 1, 1990');
</code></pre>
<h3>UNIX Timestamp</h3>
<p>If you use a website like <a href="https://www.unixtimestamp.com/" target="_blank">unixtimestamp.com</a>, you can convert your times beforehand and using these as input, will always produce the correct time regardless of timezone.</p>
<pre><code class="language-javascript">var myBirthday = ('631180800');
</code></pre>
<h3>Specify <code>GMT+0:00</code> Time Zone</h3>
<p>When inputting a more human-readable datetime stamp, follow it with <code>GMT+0:00</code> and this will force a normalized timezone, regardless of the computer's settings.</p>
<pre><code class="language-javascript">var myBirthday = ('January 1, 1990 GMT+0:00');
</code></pre>
<h2>References</h2>
<ul>
<li><a href="https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone" target="_blank">https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone</a></li>
</ul>
<p class="last-modified">Last modified: 202206101419</p></article></main><footer><nav><a href="index.html">Sitemap</a></nav><div class="social"><p>Built using <a href="http://codeberg.org/milofultz/swiki" target="_blank" rel="noopener noreferrer">{{SWIKI}}</a></p><p><a href="http://codeberg.org/milofultz/" target="_blank" rel="noopener noreferrer">Codeberg</a></p><p><a href="http://milofultz.com/" target="_blank" rel="noopener noreferrer">milofultz.com</a></p><p><a href="https://merveilles.town/@milofultz" target="_blank" rel="me noopener noreferrer">Mastodon</a></p></div></footer></body></html>