Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-24-2012, 12:46 AM   PM User | #1
ufocprez
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ufocprez is an unknown quantity at this point
Need help: getTimeZoneOffset

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>
ufocprez is offline   Reply With Quote
Old 05-24-2012, 02:51 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 05-24-2012, 03:02 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,528
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:33 AM.


Advertisement
Log in to turn off these ads.