In this article,We can show time and date using javascript.
Output : This Script help you to show time and date. Mon Jul 08 2013 13:18:03
NOTE:THE TIME SHOW HERE IN THIS OUTPUT IS THE TIME WHEN I POST THIS ARTICLE.
now = new Date()
JavaScript provides a Date object that makes dealing with dates and times relatively easy.In this line a new Date object named now is created using the new object creation operator. This is a little different from how objects have been used in the examples up until now. String objects can be created by assigning literal text to a variable and then treating that variable as though it has properties and methods. The document and Math objects are created by the browser and interpreter environments and are ready to use by any script executed by them. The Date object however is designed to provide a way to create Date objects for a given date or time. The sample line creates a Date object named now that contains the date and time when the now Date was created. Like the String, document, and Math objects the Date object provides numerous useful methods for working with dates and times.
JavaScript provides a Date object that makes dealing with dates and times relatively easy.In this line a new Date object named now is created using the new object creation operator. This is a little different from how objects have been used in the examples up until now. String objects can be created by assigning literal text to a variable and then treating that variable as though it has properties and methods. The document and Math objects are created by the browser and interpreter environments and are ready to use by any script executed by them. The Date object however is designed to provide a way to create Date objects for a given date or time. The sample line creates a Date object named now that contains the date and time when the now Date was created. Like the String, document, and Math objects the Date object provides numerous useful methods for working with dates and times.
hour = now.getHours()
Just one of the useful methods provided by the Date object is the getHours() method. getHours()returns the hour of the time stored in the now variable. The hour is between 0 (midnight) and 23 (11 PM). If the time was between noon and less than 1 PM (13 hours) getHours() will return 12.
Just one of the useful methods provided by the Date object is the getHours() method. getHours()returns the hour of the time stored in the now variable. The hour is between 0 (midnight) and 23 (11 PM). If the time was between noon and less than 1 PM (13 hours) getHours() will return 12.
Here is a example,
<HTML>
<HEAD>
<TITLE>How To Show Time and Date Using Javascript Simple Eample</TITLE>
</HEAD>
<BODY>
<PRE>This Script help you to show time and date.
<SCRIPT Language="JavaScript">
now = new Date() //create a Date object named: now
hour = now.getHours() //hours range from 0 to 23.
//0 is midnight to before 1 AM.
document.write(now)
</SCRIPT>
</PRE>
</BODY>
</HTML>
Output : This Script help you to show time and date. Mon Jul 08 2013 13:18:03
NOTE:THE TIME SHOW HERE IN THIS OUTPUT IS THE TIME WHEN I POST THIS ARTICLE.