I'm exactly 7 hours behind GMT, so my result is: So far, all we've done with Date is get the current date, and convert it to a String for display in a web page. The Date() constructor function creates a date that represents now, if you don't pass in any arguments.But you can also create specific dates, by passing in the year, month, day, hours, minutes, seconds, and even milliseconds of a specific date and time you want. Because in Java Script, the months start at 0 and go to 11.You can use the Date methods, get Timezone Offset() and to UTCString() to help figure out differences in the local time where you are (or where someone using your web page is), and the UTC time.Let's update to use these methods to show how many hours we are from UTC time: Save it, open again, and click .Here, we created a new Date object that, by default, represents the present time, and then changed the year to 2020, the hour to 1pm, and the minute to 3 minutes after 1pm.
That number is kind of ugly when we display it because of the precision of the number after the decimal point.
The number of milliseconds to the date in 2020 will be longer than the number of milliseconds to now (assuming it's still before 2020 of course! So we subtract the milliseconds to now from the milliseconds to the date in 2020 to get the difference in milliseconds.
Then, we convert from milliseconds to days by dividing by 1000 (the number of milliseconds in a second), then 60 (the number of seconds in a minute), then 60 again (the number of minutes in an hour), and then 24 (the number of hours in a day).
For instance, compare the way the date string is displayed using to Locale String() with how it was displayed using to String() (above): In the previous example using to String(), in the date and time information displayed in the web page, you can see the time zone information: GMT-0700 (PDT)?
I'm in the Pacific time zone in the United States, so my time is currently 7 hours behind the GMT (Greenwich Mean Time) measured from Greenwich, in London, England.