<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Philippe Batigne</title>
    <description>The latest articles on Forem by Philippe Batigne (@philthedev).</description>
    <link>https://forem.com/philthedev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F863795%2Fd2992b9e-007b-40b0-b0ec-234849add365.jpeg</url>
      <title>Forem: Philippe Batigne</title>
      <link>https://forem.com/philthedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/philthedev"/>
    <language>en</language>
    <item>
      <title>Fix Javascript Date Woes</title>
      <dc:creator>Philippe Batigne</dc:creator>
      <pubDate>Wed, 18 May 2022 14:05:27 +0000</pubDate>
      <link>https://forem.com/philthedev/fix-javascript-date-woes-38hl</link>
      <guid>https://forem.com/philthedev/fix-javascript-date-woes-38hl</guid>
      <description>&lt;p&gt;If you've ever worked with dates returned from an API in javascript/typescript, you've probably dealt with the "ugh, why did it convert to UTC &lt;em&gt;then&lt;/em&gt; add the timezone". I found this helpful function that will take any Date and apply the Timezone difference while retaining the original time.&lt;/p&gt;

&lt;p&gt;For example, without this function if you give the Date class 1/1/2022 12:00AM, people in the EST Timezone will see 12/31/2021 6:00PM EST.&lt;/p&gt;

&lt;p&gt;With this function, if you give the Date class if you give 1/1/2022 12:00AM, people in the EST Timezone will see  1/1/2022 12:00AM EST.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://stackoverflow.com/a/39209842/864596"&gt;Code originally found from StackOverflow&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newDateInCurrentTimezone = (date: Date | string) =&amp;gt; {
  const newDate = new Date(date);
  const userTimezoneOffset = newDate.getTimezoneOffset() * 60000;
  return new Date(newDate.getTime() + userTimezoneOffset);
};

export default newDateInCurrentTimezone;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gist: &lt;a href="https://gist.github.com/phil-the-dev/eba6cdbf170822fbdee637087080ce71"&gt;https://gist.github.com/phil-the-dev/eba6cdbf170822fbdee637087080ce71&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
