<!DOCTYPE html>
<title>Current time</title>
<time id="time"></time>
<script language="javascript">
/*Create a JavaScript object for the current time,then extract the desired parts, then join them again in the desired format.*/
var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
time = hours + ":" + minutes + " " + suffix;
// Output
document.getElementById("time").innerHTML = time;
</script>
<title>Current time</title>
<time id="time"></time>
<script language="javascript">
/*Create a JavaScript object for the current time,then extract the desired parts, then join them again in the desired format.*/
var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
time = hours + ":" + minutes + " " + suffix;
// Output
document.getElementById("time").innerHTML = time;
</script>
No comments:
Post a Comment