Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

34
Views
JS Timezone not changing

I am trying to run the following code however I cannot get the correct output. This script is supposed to be able to change the date and timezone based up the parameters set, however when outputted the time will show correctly for the timezone but the timezone name will always display my local timezone despite it being referenced to use the timezone that has been set in the first time. The timezone is set for EST As you see with the code the timezone is set to EST however the "t" which displays the text version of the timezone is displaying the local timezone and now using the one specified on line one.

function init() {
  est = new Date().toLocaleString("en-us", { timeZone: "America/New_York" }); // sets timezone to EST
  d = new Date(est); // Declares a new date object
  h = d.getHours();
  m = d.getMinutes();
  s = d.getSeconds();
  t = d.toLocaleString('en-us', { timeZoneName: 'short' }).split(' ').pop();
  clock();
  day = d.getDate();
  month = d.getMonth();
  year = d.getFullYear();
};
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.