Using javascript can easily display the local time on the page, but can I display the time in different time zones on the page? The answer is yes! We only need to do some simple date calculation to get the time of different time zones. The following is a detailed explanation.
Use the date object to get the local time
D = new date (); localtime = D. gettime (); // call the gettime () method of the data () object to display the number of milliseconds between January 1, 1970 and now.
Next, use the gettimezoneoffset () method of the data () object to find the local time offset value. By default, this method displays the result of Time Zone offset values in minutes, so you need to convert this value to milliseconds in an earlier calculation.
Localoffset = D. gettimezoneoffset () * 60000;
Then, the offset of the current time and the time zone is added to obtain the International Standard Time (expressed in milliseconds, because the calculation is still required, so no conversion is performed here ), then, add the offset of the time zone you want to know, get the time of that time, and then convert it to a time string using the date object.
UTC = localtime + localoffset; // obtain the International Standard Time Offset = 5.5; calctime = UTC + (3600000 * offset); ND = new date (calctime); document. write ('specifies the time zone: '+ nd. tolocalstring ());