Finding your timezone
The output will be (depending on the day you read this blogpost and/or run this program):
Note that the Date object contains the time as well as the date. To find the timezone, once your Date object is created, use the getTimezoneOffset() method:
The output is:
What does 240 mean? 240 is the difference between Coordinated Universal Time (UTC) and local time in minutes. In other words, this is 240/60 = 4 hours behind UTC (because the output is positive). In other words, EDT is 4 hours behind UTC.
(Note that this will not always be the case because the United States adjusts clocks for daylight savings.)
If the returned value is positive, this means that the given time zone is behind UTC. If the returned value is negative, this means that the given time zone is ahead of UTC.
Try running this program in your time zone and see what values you obtain and write to us about it!
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.