How to display the time in human readable format 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

<title>Time in JavaScript</title>
<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);

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]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s