| | |
DateTime - TimeZone conversion with Javascript. Partially working!
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2006
Posts: 4
Reputation:
Solved Threads: 0
Greetings,
I need help with the javascript below. So far, I am able to pass the date through a pop-up calender and this script receives the date in format of "28 Aug 2006 11:47 PM" as a string. I then split the string and take each field for further processing. The problem is that, when the time output is 12:xx AM (only), the date, month and year part are ommited. Example :- if the input is "28 Aug 2006 03:30 AM" then the output becomes "12:00 AM" otherwise when the output is not 12.xx it works just fine. Note that date, month and year are not there in the output when it is 12:00AM
The code for your review is as below. I am using "convertdate" to change display the time in different time zones in HTML.
I need help with the javascript below. So far, I am able to pass the date through a pop-up calender and this script receives the date in format of "28 Aug 2006 11:47 PM" as a string. I then split the string and take each field for further processing. The problem is that, when the time output is 12:xx AM (only), the date, month and year part are ommited. Example :- if the input is "28 Aug 2006 03:30 AM" then the output becomes "12:00 AM" otherwise when the output is not 12.xx it works just fine. Note that date, month and year are not there in the output when it is 12:00AM
The code for your review is as below. I am using "convertdate" to change display the time in different time zones in HTML.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript"> function GetMonth(intMonth){ var MonthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") return MonthArray[intMonth] } function disp_time(offset){ var time = document.createoutage.isttime.value; var timesplit = time.split(" "); var date = timesplit[0]; var month = timesplit[1]; var year = timesplit[2]; var hhmm = timesplit[3]; var hours = timesplit[3].split(":"); var hh = hours[0]; var mm = hours[1]; //var ss = hours[2]; var AMorPM = timesplit[4]; if (AMorPM=="PM") { if (parseInt(hh,10)==12) hh=12; else hh=parseInt(hh,10)+12; } else if (AMorPM=="AM") { if (hh==12) hh-=12; hh=parseInt(hh,10); } var TimezoneOffset = offset // adjust for time zone var timetime = month+" "+date+", "+year+" "+hh+":"+mm+":"+"00"; var localTime = new Date(timetime); var ms = localTime.getTime()+ (localTime.getTimezoneOffset() * 60000)+ TimezoneOffset * 3600000; var time = new Date(ms) var month = time.getMonth(); month = parseFloat(month)+1; var date = time.getDate(); var hour = time.getHours() ; var minute = time.getMinutes(); var curTime = date+" "+GetMonth(time.getMonth())+" "+ ((hour > 12) ? hour - 12 : hour) if(hour==0) curTime = "12" curTime += ((minute < 10) ? ":0" : ":") + minute curTime += (hour >= 12) ? " PM" : " AM" return curTime; } function convertdate() { var esttime = disp_time('-4'); var edttime = disp_time('-4'); var cettime = disp_time('+2'); document.createoutage.esttime.value=esttime; document.createoutage.edttime.value=edttime; document.createoutage.cettime.value=cettime; } </script>
•
•
Join Date: Aug 2006
Posts: 4
Reputation:
Solved Threads: 0
Ok, I resolved this myself. I had to change the code down below to this...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var hour = time.getHours() ; var minute = time.getMinutes(); var curTime = date+" "+GetMonth(time.getMonth())+" "; if(hour==0) { hour = "12";} curTime += ((hour > 12) ? hour - 12 : hour); curTime += ((minute < 10) ? ":0" : ":") + minute; curTime += (hour >= 12) ? " PM" : " AM";
![]() |
Similar Threads
- Javascript links not working (Web Browsers)
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
- javascript code not working in mozillafirefox (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Alternating backgrounds?
- Next Thread: close event for firefox
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta browser captchaformproblem cart checkbox child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming prototype redirect runtime safari scale scriptlets scroll search security select shopping size software toggle unicode w3c web windowofwords wysiwyg \n





