| | |
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 ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child close column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword hint html htmlform ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl listbox math media microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player post problem progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





