JSFiddle - React, Tailwind, and code Playground

by Thomas Jackson

HTML

<div id="newStr"></div><br>
<div id="newDate"></div>
This date is not accurate for the hard-coded date for me in the EST timezone, if all we wanted to do was enter January 1st and not worry about the time.  It reverts the date to Dec. 31st, 19:00, for me.
<br/><br/>
<div id="newFormat1"></div><br/>
<div id="newFormat2"></div><br/>
<div id="newFormat3"></div>

JavaScript

var timeStr = "2000-01-01T00:00:00.0Z";
var intermediate = timeStr.split("T");
var newStr, newDate, newFormat, anotherNewFormat, andAnotherFormat, goodDate;

newStr = intermediate[0].split("-").join("/") + " " + intermediate[1].split(".")[0] + " GMT";
$('#newStr').text('Hard-coded date: ' + newStr);

newDate = new Date(newStr);
$('#newDate').text('Local time: ' + newDate);

newFormat = (1 + newDate.getUTCMonth()) + "/" + newDate.getUTCDate() + "/" + newDate.getFullYear() + " " + newDate.getUTCHours() + ":" + newDate.getUTCMinutes() + ":" + newDate.getUTCSeconds() + "." + newDate.getUTCMilliseconds();
$('#newFormat1').text('New Format #1 (year gives me 1999 instead of 2000, because I am in EST, but leaves the date as the UTC date of 1/1): ' + newFormat);

//out.textContent += newFormat + '\n';

newStr = intermediate[0].split("-").join("/") + " " + intermediate[1].split(".")[0]; // needs + " GMT"; here
newDate = new Date(newStr);
anotherNewFormat = (1 + newDate.getUTCMonth()) + "/" + newDate.getUTCDate() + "/" + newDate.getFullYear() + " " + newDate.getUTCHours() + ":" + newDate.getUTCMinutes() + ":" + newDate.getUTCSeconds() + "." + newDate.getUTCMilliseconds();
$('#newFormat2').text('New Format #2 (wrong hours, gives me 5): ' + anotherNewFormat);

//This is how I handled it
timeStr = "2000-01-01T05:00:00.0Z"; // made it 5 a.m.
intermediate = timeStr.split("T");
newStr = intermediate[0].split("-").join("/") + " " + intermediate[1].split(".")[0] + " GMT";
andAnotherFormat = new Date(newStr);
goodDate = andAnotherFormat.getMonth()+1 + "/" +  andAnotherFormat.getDate() + "/" + andAnotherFormat.getFullYear() + " " + andAnotherFormat.getHours() + ":" + andAnotherFormat.getMinutes();
$('#newFormat3').text('New Format #3 (right day and time for EST): ' + andAnotherFormat + ", formatted: " + goodDate);

//out.textContent += newFormat + '\n';