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

Reblog this post [with Zemanta]


Tags: , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.