Use Following Code for to get current time with AM & PM format using JavaScript.
<div id="current_date_class"></div>
<script type="text/javascript">
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var ampm = (hours>=12)?'pm':'am';
hours = hours%12;
hours = hours?hours:12;
hours = hours<10?'0'+hours:hours;
minutes = minutes<10?'0'+minutes:minutes;
var time = hours+" : "+minutes+" "+ampm;
document.getElementById("current_date_class").innerHTML=time;
</script>
<div id="current_date_class"></div>
<script type="text/javascript">
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var ampm = (hours>=12)?'pm':'am';
hours = hours%12;
hours = hours?hours:12;
hours = hours<10?'0'+hours:hours;
minutes = minutes<10?'0'+minutes:minutes;
var time = hours+" : "+minutes+" "+ampm;
document.getElementById("current_date_class").innerHTML=time;
</script>
No comments:
Post a Comment