title: How to calculate average time
body: <p>how to calculate average time with 11:59:00 PM and 12:00:00 AM so that it can be 11:59:30 PM. currently this code is giving me 11:59:30 AM</p>
  
  <pre><code>       var convertTimeToMilliSecondsTest = function(time) {
                    var startDate = "1970/01/01";                         
         if(time.indexOf("AM") != -1) {
            newTime = time.replace("AM", " AM");
         } else if(time.indexOf("PM") != -1) {
            newTime = time.replace("PM", " PM");
         }
            var dateString = startDate + " " + newTime;
            var date = new Date(dateString.replace(/-/g, '/'));                                 
            return date.getTime();
         }
  
           var calculateAverageTimeToBed = function(dataset) {
                   var totalTimeInMilliSeconds = 0;
  
                   for(var i = 0;i &lt; dataset.length; ++i) {
                         totalTimeInMilliSeconds += convertTimeToMilliSecondsTest(dataset[i].startTime);
                   }
  
                   var averageTimeInBed = totalTimeInMilliSeconds / dataset.length;
  
                   return averageTimeInBed;
            }
  </code></pre>