• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 18. The Date, Time, and String Objects > Working with the Date Object

Working with the Date Object

You can see the various methods of the Date object in Table 18.1, and they’re great for working with dates. In fact, we’ve already used the Date object in Chapter 16, “Dynamic HTML: Changing Web Pages On-the-Fly”—in the JavaScript Café, which responds to the local time of day on the user’s computer to display one of three menus: breakfast, lunch, or dinner, using a Date object. Here’s how that works. When you create a Date object without any parameters, the created date corresponds to the current date:

<HTML> 
    <HEAD> 
        <TITLE> 
            Welcome to the JavaScript Café 
        </TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            var currentDate = new Date()
					var currentHour = currentDate.getHours() 
            document.write( "<CENTER>") 
            document.write( "<H1>") 
            document.write( "Welcome to the JavaScript Café") 
            document.write( "</H1>") 
            document.write( "</CENTER>")  
    if (currentHour < 5 || currentHour > 23){ 
        document.write( "<CENTER>") 
        document.write( "<H1>") 
        document.write( "Sorry, we're closed now." ) 
        document.write( "</H1>") 
        document.write( "</CENTER>") 
    } 
. 
. 
. 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint