JSFiddle - React, Tailwind, and code Playground

by Sivasakthi Chandrasekaran

JavaScript

var now = new Date;
var utc_timestamp = now.toUTCString();
var edt =convertServerDateToLocal(utc_timestamp);
var year = now.getUTCFullYear();
var month =now.getMonth();
var day =now.getDate();
var hour =now.getHours();
var minute =now.getMinutes();
var am_pm =now.getMinutes();
document.write("EDT timestamp " + edt)
document.write("<br/>")
document.write("Local timestamp " + now)
document.write("<br/>")
document.write("EDT timestamp  " + utc_timestamp)
document.write("<br/>")
document.write("EDT timestamp year " + year)
document.write("<br/>")
document.write("EDT timestamp month " + month)
document.write("<br/>")
document.write("EDT timestamp day " + day)
document.write("<br/>")
document.write("EDT timestamp hour " + hour)
document.write("<br/>")
document.write("EDT timestamp minute " + minute)

function convertServerDateToLocal(dateInput) {
  // EST - UTC offset: 5 hours
  var offset = -4.0,
      /*
        - calculate the difference between the server date and UTC
        - the value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC.
        - the time-zone offset is the difference, in minutes, between UTC and local time
        - 60000 milliseconds = 60 seconds = 1 minute
      */
      serverDate = new Date(dateInput),
      utc = serverDate.getTime() - (serverDate.getTimezoneOffset() * 60000),
      /*
        - apply the offset between UTC and EST (5 hours)
        - 3600000 milliseconds = 3600 seconds = 60 minutes = 1 hour
      */
      clientDate = new Date(utc + (3600000 * offset));
  return clientDate.toLocaleString();
}