Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

format time to am pm

function formatAMPM(date: Date) {
  var hours = date.getUTCHours();
  var minutes: string | number = date.getUTCMinutes();
  var ampm = hours >= 12 ? 'pm' : 'am';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0' + minutes : minutes;
  var strTime = hours + ':' + minutes + ' ' + ampm;
  return strTime;
}
 
PREVIOUS NEXT
Tagged: #format #time #pm
ADD COMMENT
Topic
Name
3+9 =