am pm after the time in html

Solutions on MaxInterview for am pm after the time in html by the best coders in the world

showing results for - "am pm after the time in html"
Mya
06 Jan 2019
1var inputEle = document.getElementById('timeInput');
2
3
4function onTimeChange() {
5  var timeSplit = inputEle.value.split(':'),
6    hours,
7    minutes,
8    meridian;
9  hours = timeSplit[0];
10  minutes = timeSplit[1];
11  if (hours > 12) {
12    meridian = 'PM';
13    hours -= 12;
14  } else if (hours < 12) {
15    meridian = 'AM';
16    if (hours == 0) {
17      hours = 12;
18    }
19  } else {
20    meridian = 'PM';
21  }
22  alert(hours + ':' + minutes + ' ' + meridian);
23}