Java Scripts Forum  

Go Back   Java Scripts Forum > Java > Java in General (beginner)

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 10-07-2008, 01:26 AM
Justan Justan is offline
Administrator
 
Join Date: Sep 2008
Posts: 12
Default 1.1.2 Date and time display

The following fragment:
var d = new Date
writeLog(d.toLocaleString())
produces output similar to the following.
Fri Oct 23 10:29:05 1998
The first line creates a variable d as a new Date object, or more accurately, as a new instance of a Date object. The second line uses the Date toLocaleString() method of the Date object to display local date and time information. This batch script could be written as a program script as shown in the following fragment.
function main()
{
var d = new Date;
writeLog(d.toLocaleString());
}
The main() function, if it exists, is the first function to be executed in a script. This script, using a structured programming style, produces the exact same result as the first two lines, which follow a batch style. The following fragment is another variation that produces the same result.
var d = new Date;
function main()
{
writeLog(d.toLocaleString());
}
Remember that lines of script outside of functions are executed before the main() function. The following fragment is yet another variation.
function main()
{
DisplayTime();
}
function DisplayTime()
{
var d = new Date;
writeLog(d.toLocaleString());
}
To repeat, the first fragment shown consists of two lines of code written as a simple batch script. The fragments, shown after it, are all written as program scripts. All of the fragments accomplish the same thing, namely, displaying local day, date, and time information. All fragments work equally well. What are the differences? If a user wanted a simple script to display date and time information, then the first batch script would likely be the best choice. However, if a user wanted to write a more involved program, one in which the display of the date and time was only a small part, then one of the program scripts would be the best choice. Remember, Javascript scripts may be as simple or as powerful as a user chooses.
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:33 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.