<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript current time (AM/PM)</title>
</head>
<body>
<script type="text/javascript">
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var am_pm = "AM";
if (hours >= 12) {
am_pm = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
document.write("Current Time: ");
document.write("Current Time: " + hours + ":" + minutes + " " + am_pm);
</script>
</body>
</html>