View Full Version : Need help: getTimeZoneOffset

05-24-2012, 01:46 AM
I copied this code from an exisiting script... I'm not much of coder. It returns the correct date, but the time is 7+ hours ahead of my local time.

var mydate = new Date();
localOffset = mydate.getTimezoneOffset() * 60000;
myTZ = mydate + localOffset;
var myTZStr = new java.text.SimpleDateFormat("yyyyMMddHHmm").format
var myTZStrZ = myTZStr + "Z";

task.logmsg("**** myTZStr = " + myTZStr + "Z"); else

05-24-2012, 03:51 AM
This is Javascript code, not Java. Moving from Java to javascript.
Gotta be to do with the myTZ usage. Javascript is client language, so it draws its information from the client machine.

05-24-2012, 04:02 AM
That code is adding the timezone offset to the current time to give the GMT time before it passes the date to Java for formatting.

So if it is displaying a date 7 hours ahead of your local time it simply means that your compute thinks it are located in the timezone that is seven hours behind GMT.