
How can we display current date and time using javascript?

<html>
<head>
<title>Current date and time</title>
</head>
<script type="text/javascript">
var todayDate=new Date();
var date=todayDate.getDate();
var month=todayDate.getMonth()+1;
var year=todayDate.getFullYear();
var hours=todayDate.getHours();
var minutes=todayDate.getMinutes();
var seconds=todayDate.getSeconds();
document.writeln(todayDate);
document.writeln("Todays Date :- " + date + "/" + month + "/" + year);
document.writeln("Time :- "+ hours + " : " + minutes + " : " + seconds);
</script>
</html>
Description: In javascript whenever you write new Date() it shows the current date in standard format
with current day,date,time and GMT.You can have your own format.
getDate() shows current date (eg:suppose today is 12-05-2012 then you will get 12 by getDate())
getMonth() shows current month (eg: 5)
getFullYear() shows current year as 2012.
getHours() shows current hours.
getMinutes() shows current minutes.
getSeconds() shows current seconds.
After getting date ,month ,year and time you can print these according to desired format.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.