Output date and time in a human readble form : Date Get « Date Time « JavaScript DHTML






Output date and time in a human readble form

  

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
function gettime() {
    var date= new Date();
    var hr = date.getHours();
    var m = date.getMinutes();
    var s = date.getSeconds();
    var ampm="AM";
    if (hr > 11) 
    {
        ampm="PM"
    }
    if (hr > 12) 
    {
        hr -= 12
    }
    if(m < 10)
    {
        m = "0" + m
    }
    if(s < 10)
    {
        s = "0" + s
    }
    document.clockform.clock.value = hr + ":" + m + ":" + s + " " +ampm;
    setTimeout("gettime()",100)
}
</script>
</head>
<body onload="gettime()">
<form name="clockform">
<input type="text" name="clock">
</form>
</body>
</html>

   
    
  








Related examples in the same category

1.Get Day
2.Get Seconds
3.Get Month
4.Get Milliseconds
5.Get Full Year
6.Get Year
7.Get Time
8.To Date Source
9.Convert Date to Locale String()
10.Value Of a Date
11.Readable date value
12.Make the time readable
13.Local time and local date
14.Use toPrecision to set the date precision