473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3. "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
  4.  
  5. <HTML lang=en xml:lang="en"
  6. xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Support</TITLE>
  7. <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
  8. <META http-equiv=Content-Style-Type content=text/css>
  9. <script language="JavaScript" type="text/javascript">
  10.  
  11.  
  12. var tzo=(new Date().getTimezoneOffset()/60)*(-1); //Time Zone offset
  13.  
  14. /**************************
  15. // This will display all UNIX Time to normal time
  16. **************************/
  17. function convertToDate() {
  18.        var recentTable = document.getElementById("stripedTable");
  19.  var recentTds =  recentTable.getElementsByTagName("td");
  20.        for (i = 0; i<recentTds.length; i++) {
  21.        var tdValues = recentTds[i].lastChild.nodeValue;
  22.    var tdNewValues = document.createTextNode("I'm working");
  23.                if ((!isNaN(tdValues)) && (tdValues != " ")) {
  24.  
  25.        alert(tdValues);
  26.    }
  27.        }
  28. }
  29.  
  30.  
  31.  
  32. function unixtimetodate() {
  33.  
  34.  var allInputs = document.getElementsByTagName("input");
  35.        for (i = 0; i<allInputs.length; i++) {
  36.                        if (allInputs[i].className == "unixtime") {
  37.  
  38.        var myDate = new Date( (dateString) *1000);
  39.                        document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
  40.                        var utc = 0;
  41.  
  42.        // This creates a unixtime in UTC
  43.        if (utc) {
  44.                dateString = myDate.toGMTString();
  45.  
  46.                // This creates a unixtime in localtime (accounting for the local timezone)
  47.        } else {
  48.                dateString = myDate.toLocaleString();
  49.        }
  50.        get_eid(dateString) = dateString;
  51.        return false;
  52. }
  53.  
  54. function datetounixtime() {
  55.        var utc = 0;
  56.        // This creates a unixtime in UTC
  57.        if (utc) {
  58.                var humDate = new Date(
  59.                        Date.UTC(
  60.                                get_eid('vyy').value,
  61.                                get_eid('vmm').value - 1,
  62.                                get_eid('vdd').value,
  63.                                get_eid('vhh').value,
  64.                                get_eid('vmin').value,
  65.                                get_eid('vsec').value
  66.                                )
  67.                        );
  68.                get_eid(dateString) = (humDate.getTime()/1000.0);
  69.  
  70.                // This creates a unixtime in localtime (accounting for the local timezone)
  71.        } else {
  72.                var humDate = new Date(
  73.                        get_eid('vyy').value,
  74.                        get_eid('vmm').value - 1,
  75.                        get_eid('vdd').value,
  76.                        get_eid('vhh').value,
  77.                        get_eid('vmin').value,
  78.                        get_eid('vsec').value
  79.                        );
  80.                get_eid(dateString) = (humDate.getTime()/1000.0);
  81.        }
  82.        return false;
  83. }
  84.  
  85. function get_month($num) {
  86.        if ($num == 1) { return "Jan"; }
  87.        if ($num == 2) { return "Feb"; }
  88.        if ($num == 3) { return "Mar"; }
  89.        if ($num == 4) { return "Apr"; }
  90.        if ($num == 5) { return "May"; }
  91.        if ($num == 6) { return "Jun"; }
  92.        if ($num == 7) { return "Jul"; }
  93.        if ($num == 8) { return "Aug"; }
  94.        if ($num == 9) { return "Sep"; }
  95.        if ($num == 10) { return "Oct"; }
  96.        if ($num == 11) { return "Nov"; }
  97.        if ($num == 12) { return "Dec"; }
  98. }
  99.  
  100. function get_eid(name) {
  101.        var ret = document.getElementById(name);
  102.        return ret;
  103. }
  104.  
  105. function startup() {
  106.        var dt = new Date();
  107.        var month = dt.getMonth() + 1;
  108.        var year = dt.getFullYear();
  109.        var mday = dt.getDate();
  110.  
  111.        var hour = dt.getHours();
  112.        var min = dt.getMinutes();
  113.        var sec = dt.getSeconds();
  114.  
  115.        // This give MILLIseconds
  116.        var epoch = ((dt.getTime() - dt.getMilliseconds()) / 1000);
  117.  
  118.        get_eid('vyy').value = year;
  119.        get_eid('vmm').value = month;
  120.        get_eid('vdd').value = mday;
  121.  
  122.        get_eid('vhh').value = hour;
  123.        get_eid('vmin').value = min;
  124.        get_eid('vsec').value = sec;
  125.  
  126.        get_eid('unixtimestamp').value = epoch;
  127.  
  128.                        }
  129.                }
  130. }
  131.  
  132. function addLoadEvent(func) {
  133.  var oldonload = window.onload;
  134.  if (typeof window.onload != 'function') {
  135.    window.onload = func;
  136.  } else {
  137.    window.onload = function() {
  138.      oldonload();
  139.      func();
  140.    }
  141.  }
  142. }
  143.  
  144. addLoadEvent(convertToDate);
  145. </script>
  146.  
  147.  
  148. </HEAD>
  149.  
  150.  
  151.    <table width="100%" id='stripedTable' summary="case notes and
  152. history table">
  153.                <tr>
  154.                    <td style="vertical-align: middle">
  155.                        <b><a href="case.do?caseId=C461057">C461057</a></b>
  156.                    </td>
  157.                    <td>
  158.                        testcase14<br/>
  159.                        <b>Summary:</b>7g7g7g7gg7
  160.                    </td>
  161.                    <td align="right" class="unixTime"><b>Last
  162. Updated:</b><br />1229457069</td>
  163.                </tr>
  164.                <tr>
  165.                    <td style="vertical-align: middle">
  166.                        <b><a href="case.do?caseId=C461056">C461056</a></b>
  167.                    </td>
  168.                    <td>
  169.                        test31<br/>
  170.                        <b>Summary:</b>8g8g8g8g8g8g8g
  171.                    </td>
  172.                    <td align="right"><b>Last Updated:</b><br />1229456237</td>
  173.                </tr>
  174.                <tr>
  175.                    <td style="vertical-align: middle">
  176.                        <b><a href="case.do?caseId=C461054">C461054</a></b>
  177.                    </td>
  178.                    <td>
  179.                        the<br/>
  180.                        <b>Summary:</b>0h0hhh0h0h
  181.                    </td>
  182.                    <td align="right"><b>Last Updated:</b><br />1229464275</td>
  183.                </tr>
  184.                <tr>
  185.                    <td style="vertical-align: middle">
  186.                        <b><a href="rmaCase.do?caseId=C461051">C461051</a></b>
  187.                    </td>
  188.                    <td>
  189.                        rma issue<br/>
  190.                        <b>Summary:</b>7f7g7h7f7f7g7h
  191.                    </td>
  192.                    <td align="right"><b>Last Updated:</b><br />1229711822</td>
  193.                </tr>
  194.                <tr>
  195.                    <td style="vertical-align: middle">
  196.                        <b><a href="case.do?caseId=C461026">C461026</a></b>
  197.                    </td>
  198.                    <td>
  199.                        switch problem<br/>
  200.                        <b>Summary:</b>9g9h89g76f7
  201.                    </td>
  202.                    <td align="right"><b>Last Updated:</b><br />1228512455</td>
  203.                </tr>
  204.    </table>
  205. </div>
  206. </BODY></HTML>
  207.  
  208.  
  209.  
In a perfect word, this page would look like this when a visitor
visits the page.

Expand|Select|Wrap|Line Numbers
  1. <HTML lang=en xml:lang="en"
  2. xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Support</TITLE>
  3. <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
  4. <META http-equiv=Content-Style-Type content=text/css>
  5. <script language="JavaScript" type="text/javascript">
  6.  
  7.  
  8. var tzo=(new Date().getTimezoneOffset()/60)*(-1); //Time Zone offset
  9.  
  10. /**************************
  11. // This will display all UNIX Time to normal time
  12. **************************/
  13. function convertToDate() {
  14.        var recentTable = document.getElementById("stripedTable");
  15.  var recentTds =  recentTable.getElementsByTagName("td");
  16.        for (i = 0; i<recentTds.length; i++) {
  17.        var tdValues = recentTds[i].lastChild.nodeValue;
  18.    var tdNewValues = document.createTextNode("I'm working");
  19.                if ((!isNaN(tdValues)) && (tdValues != " ")) {
  20.  
  21.        alert(tdValues);
  22.    }
  23.        }
  24. }
  25.  
  26.  
  27.  
  28. function unixtimetodate() {
  29.  
  30.  var allInputs = document.getElementsByTagName("input");
  31.        for (i = 0; i<allInputs.length; i++) {
  32.                        if (allInputs[i].className == "unixtime") {
  33.  
  34.        var myDate = new Date( (dateString) *1000);
  35.                        document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
  36.                        var utc = 0;
  37.  
  38.        // This creates a unixtime in UTC
  39.        if (utc) {
  40.                dateString = myDate.toGMTString();
  41.  
  42.                // This creates a unixtime in localtime (accounting for the local timezone)
  43.        } else {
  44.                dateString = myDate.toLocaleString();
  45.        }
  46.        get_eid(dateString) = dateString;
  47.        return false;
  48. }
  49.  
  50. function datetounixtime() {
  51.        var utc = 0;
  52.        // This creates a unixtime in UTC
  53.        if (utc) {
  54.                var humDate = new Date(
  55.                        Date.UTC(
  56.                                get_eid('vyy').value,
  57.                                get_eid('vmm').value - 1,
  58.                                get_eid('vdd').value,
  59.                                get_eid('vhh').value,
  60.                                get_eid('vmin').value,
  61.                                get_eid('vsec').value
  62.                                )
  63.                        );
  64.                get_eid(dateString) = (humDate.getTime()/1000.0);
  65.  
  66.                // This creates a unixtime in localtime (accounting for the local timezone)
  67.        } else {
  68.                var humDate = new Date(
  69.                        get_eid('vyy').value,
  70.                        get_eid('vmm').value - 1,
  71.                        get_eid('vdd').value,
  72.                        get_eid('vhh').value,
  73.                        get_eid('vmin').value,
  74.                        get_eid('vsec').value
  75.                        );
  76.                get_eid(dateString) = (humDate.getTime()/1000.0);
  77.        }
  78.        return false;
  79. }
  80.  
  81. function get_month($num) {
  82.        if ($num == 1) { return "Jan"; }
  83.        if ($num == 2) { return "Feb"; }
  84.        if ($num == 3) { return "Mar"; }
  85.        if ($num == 4) { return "Apr"; }
  86.        if ($num == 5) { return "May"; }
  87.        if ($num == 6) { return "Jun"; }
  88.        if ($num == 7) { return "Jul"; }
  89.        if ($num == 8) { return "Aug"; }
  90.        if ($num == 9) { return "Sep"; }
  91.        if ($num == 10) { return "Oct"; }
  92.        if ($num == 11) { return "Nov"; }
  93.        if ($num == 12) { return "Dec"; }
  94. }
  95.  
  96. function get_eid(name) {
  97.        var ret = document.getElementById(name);
  98.        return ret;
  99. }
  100.  
  101. function startup() {
  102.        var dt = new Date();
  103.        var month = dt.getMonth() + 1;
  104.        var year = dt.getFullYear();
  105.        var mday = dt.getDate();
  106.  
  107.        var hour = dt.getHours();
  108.        var min = dt.getMinutes();
  109.        var sec = dt.getSeconds();
  110.  
  111.        // This give MILLIseconds
  112.        var epoch = ((dt.getTime() - dt.getMilliseconds()) / 1000);
  113.  
  114.        get_eid('vyy').value = year;
  115.        get_eid('vmm').value = month;
  116.        get_eid('vdd').value = mday;
  117.  
  118.        get_eid('vhh').value = hour;
  119.        get_eid('vmin').value = min;
  120.        get_eid('vsec').value = sec;
  121.  
  122.        get_eid('unixtimestamp').value = epoch;
  123.  
  124.                        }
  125.                }
  126. }
  127.  
  128. function addLoadEvent(func) {
  129.  var oldonload = window.onload;
  130.  if (typeof window.onload != 'function') {
  131.    window.onload = func;
  132.  } else {
  133.    window.onload = function() {
  134.      oldonload();
  135.      func();
  136.    }
  137.  }
  138. }
  139.  
  140. addLoadEvent(convertToDate);
  141. </script>
  142.  
  143.  
  144. </HEAD>
  145.  
  146.  
  147.    <table width="100%" id='stripedTable' summary="case notes and
  148. history table">
  149.                <tr>
  150.                    <td style="vertical-align: middle">
  151.                        <b><a href="case.do?caseId=C461057">C461057</a></b>
  152.                    </td>
  153.                    <td>
  154.                        testcase14<br/>
  155.                        <b>Summary:</b>7g7g7g7gg7
  156.                    </td>
  157.                    <td align="right" class="unixTime"><b>Last
  158. Updated:</b><br />Tue, 16 Dec 2008 19:51:09 GMT</td>
  159.                </tr>
  160.                <tr>
  161.                    <td style="vertical-align: middle">
  162.                        <b><a href="case.do?caseId=C461056">C461056</a></b>
  163.                    </td>
  164.                    <td>
  165.                        test31<br/>
  166.                        <b>Summary:</b>8g8g8g8g8g8g8g
  167.                    </td>
  168.                    <td align="right"><b>Last Updated:</b><br />Tue,
  169. 16 Dec 2008 19:37:17 GMT</td>
  170.                </tr>
  171.                <tr>
  172.                    <td style="vertical-align: middle">
  173.                        <b><a href="case.do?caseId=C461054">C461054</a></b>
  174.                    </td>
  175.                    <td>
  176.                        the<br/>
  177.                        <b>Summary:</b>0h0hhh0h0h
  178.                    </td>
  179.                    <td align="right"><b>Last Updated:</b><br />Tue,
  180. 16 Dec 2008 21:51:15 GMT</td>
  181.                </tr>
  182.                <tr>
  183.                    <td style="vertical-align: middle">
  184.                        <b><a href="rmaCase.do?caseId=C461051">C461051</a></b>
  185.                    </td>
  186.                    <td>
  187.                        rma issue<br/>
  188.                        <b>Summary:</b>7f7g7h7f7f7g7h
  189.                    </td>
  190.                    <td align="right"><b>Last Updated:</b><br />Fri,
  191. 19 Dec 2008 18:37:02 GMT</td>
  192.                </tr>
  193.                <tr>
  194.                    <td style="vertical-align: middle">
  195.                        <b><a href="case.do?caseId=C461026">C461026</a></b>
  196.                    </td>
  197.                    <td>
  198.                        switch problem<br/>
  199.                        <b>Summary:</b>9g9h89g76f7
  200.                    </td>
  201.                    <td align="right"><b>Last Updated:</b><br />Fri,
  202. 05 Dec 2008 21:27:35 GMT</td>
  203.                </tr>
  204.    </table>
  205. </div>
  206. </BODY></HTML>
  207.  
But, if the user was Pacific Standard time, the time would be 8 hours
earlier and GMT would be replaced with PST

Please help,
Dec 22 '08 #1
1 2303
Dormilich
8,658 Expert Mod 8TB
what is the problem actually, I didn't get that.

regards
Dec 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
2
by: MLH | last post by:
I would like to be able to look up any 5-digit ZIP in a table that would show the correct time zone for the area. For example, I would like to look up 91915 in the table and see something that...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
1
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
10
by: Marc Pelletier | last post by:
Hello, I am writing an application that does some simple astronomical calculations. One of the variables I need is the number of hours passed in this year. I've written the following function ...
4
by: P. George | last post by:
i have a table with a 'timstamp with time zone' column. when i insert into it: '18 Nov 2004 00:00:00 PST' ....it looks like: 2004-11-18 03:00:00-05
14
by: Cesar Ronchese | last post by:
Hello! I've built a program that show some dates to users. I got a problem when users have different configured time zone machines, where: - One machine that determined time zone the date...
3
by: Satish Itty | last post by:
Hi all, I have a big problem in my hands and not sure how I can fix this. Any suggestions would be greatly appreciated. I have a .NET 3 tier app developed in VS2003 and .NET 1.1. the client is a...
7
by: Steve | last post by:
Hi All I have a windows application written in VB.net 2005 The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.