How to display the time in human readable format in JavaScript?
Posted by Joys of Programming on in JavaScript
Date givesmany functions like getTime(), Date() to display the time. Date() returns an object which displays the time in the UTC format. But to display in a format of your choice
<head>
<title>Time in JavaScript</title>
</head>
<body>
<script type="text/javascript">
<!--
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;
var date1 = time.getDate();
var hour = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
document.write("Time "+ year + "-" + month+"-"+date1+" "+hour+":"+minutes+":"+seconds);
-->
</script>
</body>
You can format in any way you like. The output of the above program
Time 2009-11-30 23:0:56
Comments:
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=648aa87f-6026-47ae-8a1f-0f384cb11275)