Purpose: Find local time and UTC time offset local time UTC time offset then build the URL in the following format.
Example URL: / Actions / Sleep? Duration = 2002-10-10T12: 00: 00−05: 00
The format is based on the W3C recommendation: http://www.w3.org/TR/xmlschema11-2/#dateTime
The documentation says:
For example, 2002-10-10T12: 00: 00-05: 00 (noon on October 10, 2002, central daylight saving time, and also standard eastern time in the USA) is 2002-10-10T17: 00: 00Z, five hours later than 2002-10-10T12: 00: 00Z.
Based on my understanding, I need to find my local time using the new Date () function, then use the getTimezoneOffset () function to calculate the difference, and then attach it to the end of the line.
1. Get local time in format
var local = new Date().format("yyyy-MM-ddThh:mm:ss");
exit
2013-07-02T09:00:00
UTC 2.Get time offset per hour
var offset = local.getTimezoneOffset() / 60;
exit
7
3. Create URL (only temporary part)
var duration = local + "-" + offset + ":00";
exit:
2013-07-02T09:00:00-7:00
The above conclusion means that my local time 2013/07/02 is 9am, and the difference with UTC is 7 hours (UTC is 7 hours ahead of local time)
So far this works, but what if getTimezoneOffset () returns a negative value, like -120?
I am wondering what the format should look like in this case, because I cannot understand from the W3C document. Thank you in advance.
javascript timezone
masato-san Jul 02 '13 at 0:19 2013-07-02 00:19
source share