Translate

Wednesday, 29 November 2017

JavaScript get hh:mm:tt format i.e. hour:minute: AM/PM format from java script date

Key Code:

<script type="text/javascript" src="http://www.datejs.com/build/date.js"></script>
<script>
    function startTime() {
        document.getElementById('lblTime').innerHTML = new Date().toString("hh:mm tt");     
    }   
</script>

Design:
<body onload="startTime()">
<div style="text-align:right;">Current Time:<label id="lblTime"></label></div>
</body>




Details Code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
<script type="text/javascript" src="http://www.datejs.com/build/date.js"></script>
<script>
    function startTime() {
        document.getElementById('lblTime').innerHTML = new Date().toString("hh:mm tt");     
    }   
</script>

</head>
<body onload="startTime()">
<div id="divHeader">
<div style="text-align:right;">Current Time:<label id="lblTime"></label></div>
</div>

<div id="divBody">
<p>Wel Come</p>
</div>
<div id="divFooter">
<p> Copyright 1999-2017</p>
</div>
</body>
</html>

No comments:

Post a Comment