Time Zone Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nigelesquire
    New Member
    • Sep 2008
    • 9

    Time Zone Help

    I am in need of your assistance. I have a page with multiple unixtime
    stamps and I need to display them in readable time and date with the
    user's time zone.

    Below is the code.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
    
    <HTML lang=en xml:lang="en"
    xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Support</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <META http-equiv=Content-Style-Type content=text/css>
    <script language="JavaScript" type="text/javascript">
    
    
    var tzo=(new Date().getTimezoneOffset()/60)*(-1); //Time Zone offset
    
    /**************************
    // This will display all UNIX Time to normal time
    **************************/
    function convertToDate() {
           var recentTable = document.getElementById("stripedTable");
     var recentTds =  recentTable.getElementsByTagName("td");
           for (i = 0; i<recentTds.length; i++) {
           var tdValues = recentTds[i].lastChild.nodeValue;
       var tdNewValues = document.createTextNode("I'm working");
                   if ((!isNaN(tdValues)) && (tdValues != " ")) {
    
           alert(tdValues);
       }
           }
    }
    
    
    
    function unixtimetodate() {
    
     var allInputs = document.getElementsByTagName("input");
           for (i = 0; i<allInputs.length; i++) {
                           if (allInputs[i].className == "unixtime") {
    
           var myDate = new Date( (dateString) *1000);
                           document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
                           var utc = 0;
    
           // This creates a unixtime in UTC
           if (utc) {
                   dateString = myDate.toGMTString();
    
                   // This creates a unixtime in localtime (accounting for the local timezone)
           } else {
                   dateString = myDate.toLocaleString();
           }
           get_eid(dateString) = dateString;
           return false;
    }
    
    function datetounixtime() {
           var utc = 0;
           // This creates a unixtime in UTC
           if (utc) {
                   var humDate = new Date(
                           Date.UTC(
                                   get_eid('vyy').value,
                                   get_eid('vmm').value - 1,
                                   get_eid('vdd').value,
                                   get_eid('vhh').value,
                                   get_eid('vmin').value,
                                   get_eid('vsec').value
                                   )
                           );
                   get_eid(dateString) = (humDate.getTime()/1000.0);
    
                   // This creates a unixtime in localtime (accounting for the local timezone)
           } else {
                   var humDate = new Date(
                           get_eid('vyy').value,
                           get_eid('vmm').value - 1,
                           get_eid('vdd').value,
                           get_eid('vhh').value,
                           get_eid('vmin').value,
                           get_eid('vsec').value
                           );
                   get_eid(dateString) = (humDate.getTime()/1000.0);
           }
           return false;
    }
    
    function get_month($num) {
           if ($num == 1) { return "Jan"; }
           if ($num == 2) { return "Feb"; }
           if ($num == 3) { return "Mar"; }
           if ($num == 4) { return "Apr"; }
           if ($num == 5) { return "May"; }
           if ($num == 6) { return "Jun"; }
           if ($num == 7) { return "Jul"; }
           if ($num == 8) { return "Aug"; }
           if ($num == 9) { return "Sep"; }
           if ($num == 10) { return "Oct"; }
           if ($num == 11) { return "Nov"; }
           if ($num == 12) { return "Dec"; }
    }
    
    function get_eid(name) {
           var ret = document.getElementById(name);
           return ret;
    }
    
    function startup() {
           var dt = new Date();
           var month = dt.getMonth() + 1;
           var year = dt.getFullYear();
           var mday = dt.getDate();
    
           var hour = dt.getHours();
           var min = dt.getMinutes();
           var sec = dt.getSeconds();
    
           // This give MILLIseconds
           var epoch = ((dt.getTime() - dt.getMilliseconds()) / 1000);
    
           get_eid('vyy').value = year;
           get_eid('vmm').value = month;
           get_eid('vdd').value = mday;
    
           get_eid('vhh').value = hour;
           get_eid('vmin').value = min;
           get_eid('vsec').value = sec;
    
           get_eid('unixtimestamp').value = epoch;
    
                           }
                   }
    }
    
    function addLoadEvent(func) {
     var oldonload = window.onload;
     if (typeof window.onload != 'function') {
       window.onload = func;
     } else {
       window.onload = function() {
         oldonload();
         func();
       }
     }
    }
    
    addLoadEvent(convertToDate);
    </script>
    
    
    </HEAD>
    
    
       <table width="100%" id='stripedTable' summary="case notes and
    history table">
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461057">C461057</a></b>
                       </td>
                       <td>
                           testcase14<br/>
                           <b>Summary:</b>7g7g7g7gg7
                       </td>
                       <td align="right" class="unixTime"><b>Last
    Updated:</b><br />1229457069</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461056">C461056</a></b>
                       </td>
                       <td>
                           test31<br/>
                           <b>Summary:</b>8g8g8g8g8g8g8g
                       </td>
                       <td align="right"><b>Last Updated:</b><br />1229456237</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461054">C461054</a></b>
                       </td>
                       <td>
                           the<br/>
                           <b>Summary:</b>0h0hhh0h0h
                       </td>
                       <td align="right"><b>Last Updated:</b><br />1229464275</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="rmaCase.do?caseId=C461051">C461051</a></b>
                       </td>
                       <td>
                           rma issue<br/>
                           <b>Summary:</b>7f7g7h7f7f7g7h
                       </td>
                       <td align="right"><b>Last Updated:</b><br />1229711822</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461026">C461026</a></b>
                       </td>
                       <td>
                           switch problem<br/>
                           <b>Summary:</b>9g9h89g76f7
                       </td>
                       <td align="right"><b>Last Updated:</b><br />1228512455</td>
                   </tr>
       </table>
    </div>
    </BODY></HTML>
    In a perfect word, this page would look like this when a visitor
    visits the page.

    Code:
    <HTML lang=en xml:lang="en"
    xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Support</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <META http-equiv=Content-Style-Type content=text/css>
    <script language="JavaScript" type="text/javascript">
    
    
    var tzo=(new Date().getTimezoneOffset()/60)*(-1); //Time Zone offset
    
    /**************************
    // This will display all UNIX Time to normal time
    **************************/
    function convertToDate() {
           var recentTable = document.getElementById("stripedTable");
     var recentTds =  recentTable.getElementsByTagName("td");
           for (i = 0; i<recentTds.length; i++) {
           var tdValues = recentTds[i].lastChild.nodeValue;
       var tdNewValues = document.createTextNode("I'm working");
                   if ((!isNaN(tdValues)) && (tdValues != " ")) {
    
           alert(tdValues);
       }
           }
    }
    
    
    
    function unixtimetodate() {
    
     var allInputs = document.getElementsByTagName("input");
           for (i = 0; i<allInputs.length; i++) {
                           if (allInputs[i].className == "unixtime") {
    
           var myDate = new Date( (dateString) *1000);
                           document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
                           var utc = 0;
    
           // This creates a unixtime in UTC
           if (utc) {
                   dateString = myDate.toGMTString();
    
                   // This creates a unixtime in localtime (accounting for the local timezone)
           } else {
                   dateString = myDate.toLocaleString();
           }
           get_eid(dateString) = dateString;
           return false;
    }
    
    function datetounixtime() {
           var utc = 0;
           // This creates a unixtime in UTC
           if (utc) {
                   var humDate = new Date(
                           Date.UTC(
                                   get_eid('vyy').value,
                                   get_eid('vmm').value - 1,
                                   get_eid('vdd').value,
                                   get_eid('vhh').value,
                                   get_eid('vmin').value,
                                   get_eid('vsec').value
                                   )
                           );
                   get_eid(dateString) = (humDate.getTime()/1000.0);
    
                   // This creates a unixtime in localtime (accounting for the local timezone)
           } else {
                   var humDate = new Date(
                           get_eid('vyy').value,
                           get_eid('vmm').value - 1,
                           get_eid('vdd').value,
                           get_eid('vhh').value,
                           get_eid('vmin').value,
                           get_eid('vsec').value
                           );
                   get_eid(dateString) = (humDate.getTime()/1000.0);
           }
           return false;
    }
    
    function get_month($num) {
           if ($num == 1) { return "Jan"; }
           if ($num == 2) { return "Feb"; }
           if ($num == 3) { return "Mar"; }
           if ($num == 4) { return "Apr"; }
           if ($num == 5) { return "May"; }
           if ($num == 6) { return "Jun"; }
           if ($num == 7) { return "Jul"; }
           if ($num == 8) { return "Aug"; }
           if ($num == 9) { return "Sep"; }
           if ($num == 10) { return "Oct"; }
           if ($num == 11) { return "Nov"; }
           if ($num == 12) { return "Dec"; }
    }
    
    function get_eid(name) {
           var ret = document.getElementById(name);
           return ret;
    }
    
    function startup() {
           var dt = new Date();
           var month = dt.getMonth() + 1;
           var year = dt.getFullYear();
           var mday = dt.getDate();
    
           var hour = dt.getHours();
           var min = dt.getMinutes();
           var sec = dt.getSeconds();
    
           // This give MILLIseconds
           var epoch = ((dt.getTime() - dt.getMilliseconds()) / 1000);
    
           get_eid('vyy').value = year;
           get_eid('vmm').value = month;
           get_eid('vdd').value = mday;
    
           get_eid('vhh').value = hour;
           get_eid('vmin').value = min;
           get_eid('vsec').value = sec;
    
           get_eid('unixtimestamp').value = epoch;
    
                           }
                   }
    }
    
    function addLoadEvent(func) {
     var oldonload = window.onload;
     if (typeof window.onload != 'function') {
       window.onload = func;
     } else {
       window.onload = function() {
         oldonload();
         func();
       }
     }
    }
    
    addLoadEvent(convertToDate);
    </script>
    
    
    </HEAD>
    
    
       <table width="100%" id='stripedTable' summary="case notes and
    history table">
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461057">C461057</a></b>
                       </td>
                       <td>
                           testcase14<br/>
                           <b>Summary:</b>7g7g7g7gg7
                       </td>
                       <td align="right" class="unixTime"><b>Last
    Updated:</b><br />Tue, 16 Dec 2008 19:51:09 GMT</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461056">C461056</a></b>
                       </td>
                       <td>
                           test31<br/>
                           <b>Summary:</b>8g8g8g8g8g8g8g
                       </td>
                       <td align="right"><b>Last Updated:</b><br />Tue,
    16 Dec 2008 19:37:17 GMT</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461054">C461054</a></b>
                       </td>
                       <td>
                           the<br/>
                           <b>Summary:</b>0h0hhh0h0h
                       </td>
                       <td align="right"><b>Last Updated:</b><br />Tue,
    16 Dec 2008 21:51:15 GMT</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="rmaCase.do?caseId=C461051">C461051</a></b>
                       </td>
                       <td>
                           rma issue<br/>
                           <b>Summary:</b>7f7g7h7f7f7g7h
                       </td>
                       <td align="right"><b>Last Updated:</b><br />Fri,
    19 Dec 2008 18:37:02 GMT</td>
                   </tr>
                   <tr>
                       <td style="vertical-align: middle">
                           <b><a href="case.do?caseId=C461026">C461026</a></b>
                       </td>
                       <td>
                           switch problem<br/>
                           <b>Summary:</b>9g9h89g76f7
                       </td>
                       <td align="right"><b>Last Updated:</b><br />Fri,
    05 Dec 2008 21:27:35 GMT</td>
                   </tr>
       </table>
    </div>
    </BODY></HTML>
    But, if the user was Pacific Standard time, the time would be 8 hours
    earlier and GMT would be replaced with PST

    Please help,
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what is the problem actually, I didn't get that.

    regards

    Comment

    Working...