• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

javascript time zone is off by an hour

Q&A Forum › javascript time zone is off by an hour
0 Vote Up Vote Down
Daniel Essin asked 4 years ago
10 Answers
0 Vote Up Vote Down
Daniel Essin answered 4 years ago

I’m in the ESP8266 Web Server book on page 125.The sample code is:

    <script>
        var todays_date = new Date();
        document.getElementById(“dateTime”).innerHTML = todays_date;
    </script>

The output is:
Fri Mar 19 2021 00:01:55 GMT-0700 (Pacific Daylight Time)
 
Except that Pacific time zone is GMT-0800 and the clock time is 11:55PM PDT
 
What’s going on?

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Daniel.
I’m not sure what’s the problem.
What web browser are you using to open the file?
Regards,
Sara

0 Vote Up Vote Down
Daniel Essin answered 4 years ago

Chrome

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Do you have the right data and time set up on your computer?
Can you try to add the following between the <script> tags:

var offset = new Date().getTimezoneOffset();
console.log(offset);

After opening the file in the browser, press CTRL+Shift+J and see what is printed in the console.
Regards,
Sara

0 Vote Up Vote Down
Daniel Essin answered 4 years ago

Time on computer is correct. I’ll try your suggestion.

0 Vote Up Vote Down
Daniel Essin answered 4 years ago

The offset = 420
btw – it would be helpful if the login button redirected to this page rather than to an ad 🙂

0 Vote Up Vote Down
Daniel Essin answered 4 years ago

It’s working now. If I’m up at 11:55 PM I’ll try it again.
Thanks

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
The result of offset=420 means that your browser assumes that your local time offset is 7 hours and not 8 hours.
 
When you click on the login button, it redirects to the courses page, right? Do you see something different?
 
Regards,
Sara
 

0 Vote Up Vote Down
Daniel Essin answered 4 years ago

No,  but I should.
Fos example,  right now I’m on the thread. I got there by clicking the link in the email. Of course,  when I arrive here I am not logged in.
It says login to post,  so I click login.  When I’m done logging in,  it should return me to this thread.
In stead,  I have to go back to my email,  click the link again and then I arrive back here so I can reply. My recollection is that there is an html property called referrer. I i arrive at the login page and the referrer,  it should use that as the destination url instead of the courses page,  imho.
re the time, my searching suggests to me that this is a javascript issue. Lots of folks ask about their times being off,  some by a day,  some by an hour. I’m sure it has nothing to do with the tutorial but it confused me untilmI read up a bit on javascript.
Thanks

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Daniel.
I wasn’t aware of that issue. I receive the forum’s emails in a different format (because I have an admin account).
Thanks for telling me about that. You’re totally right. I’ll report this issue to Rui and see if we can find a solution.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 2025
  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.