About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Get...

   Browse by title articles:
   What is hot:

Loops

Get

NoScript

BaseScript

Alert

Confirm

Include
Finding Targeted Keyword Phrases Your Competitors Miss
How to Create a Custom 404 Error Page and Get Your Lost Visitors Back
Search & Replace
Prev articles12 3 45Next articles



Get


Computer & I'net articlesGet

by David Stanley    



The GET command is used to retrieve a part of the current date or time. The information is constructed from the visitor's computer settings.

The different types of GET are :

getYear( )
getMonth( )
getDate( )
getDay( )
getHours( )
getMinutes( )
getSeconds( )
The year
The month
The day of the month
The day of the week
The hour
The minutes
The seconds
4 digits
0 to 11
1 to 31
1 to 7
0 to 23
1 to 60
1 to 60
2003
11
10
3
14
41
11

To properly use this feature, a new variable has to be set using a special value.

var thedate = new Date( );

I used "thedate" as the variable name for the example. You can change it to any other name you like.

The value new Date( ) tells the browser that this variable is going to contain a specified date and/or time. It is a base setting or ground. Once that is in place, the other elements can be built on top of it.

Here is an example that shows how to print out today's date :

var thedate = new Date( );
var theyear = thedate.getYear( );
var themonth = thedate.getMonth( ) + 1;
var theday = thedate.getDate( );

document.write("Today's date is : " + theday + " / " + themonth + " / " + theyear);
The result ~ Today's date is : 10 / 12 / 2003

Here is a break down of what is happening in the example :

  1. a variable called thedate is being used to create a date and/or time value.
  2. JavaScript (being a builder script) gets more specified information to attach to thedate. In this case, the year, month and day.
  3. Notice the "+ 1" for the month variable? That's because JavaScript likes to start counting at 0 instead of 1. Don't ask me WHY that particular one and not the others. I don't know.
  4. Print out the day, month and year.
How about an example that shows a message relating to the time of day?

var thetime = new Date( );
var thehour = thetime.getHours( );

if (thehour < 12) {
document.write("It is morning");
} else if (thehour < 17) {
document.write("It is afternoon");
} else {
document.write("It is evening");
}
The result ~ It is afternoon

Here is a break down of what is happening in the example :

  1. a variable is set to collect a date/time.
  2. a variable is set to get the HOUR (0 to 23) of the day.
  3. IF the hour is less than 12 (noon), then write "Morning", else continue on.
  4. IF the hour passed 12 and is less than 17 (4 o'clock), then write "Afternoon", else continue on.
  5. IF the hour passed the first 2 tests, the hour must be greater than 17, so write "Evening".



-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.




Articles

Auto & Trucks

Business

Computer & I'net

  ·General

  ·Apache

  ·CSS

  ·Database

  ·Hardware

  ·HTML

Javascript&DHTML

  ·Linux

  ·MySQL

  ·Operating System

  ·Perl / CGI

  ·PHP

  ·Programming

  ·Publishing

  ·Search Engines

  ·Software Problems

  ·SSI

  ·Tips & Tricks

  ·Utilities

  ·Web Design

Family

Food & Drink

Gardening

Health

Other

Pets

Psychology

Spiritual

Travel

Women

 Calculators

Capital gain




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com