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.

<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>

Ok, I resolved this myself. I had to change the code down below to this...

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";
This question has already been answered. Start a new discussion instead.