Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •