...

View Full Version : Need help: getTimeZoneOffset



ufocprez
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.

<Script><![CDATA[if(conn.getAttribute("status")!=null){
if(conn.getString("status").equals("1"))
var mydate = new Date();
localOffset = mydate.getTimezoneOffset() * 60000;
myTZ = mydate + localOffset;
var myTZStr = new java.text.SimpleDateFormat("yyyyMMddHHmm").format
(myTZ);
var myTZStrZ = myTZStr + "Z";

task.logmsg("**** myTZStr = " + myTZStr + "Z"); else
ret.value="";
}]]></Script>

Fou-Lu
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.

felgall
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum