Web design creating cool web sites with html, xhtml, and css

Page 276

Chapter 11: Activating Your Pages with JavaScript

249

Method

Description

setFullYear

Specifies new year (4-digit) in date object

setHours

Specifies new hours value in date object (range 0–23)

setMinutes

Specifies new minutes value in date object (range 0–59)

setMonth

Specifies new month in date object (same as setDate)

setSeconds

Specifies new seconds in date object

setTime

Specifies time for date object in milliseconds (see getTime)

setYear

Specifies new year in date object (See note in getYear)

toLocaleString

Returns locale-based date/time string (most useful for switching date format strings to local conventions and languages, as the individual user specifies)

These methods make producing attractive output a breeze, because they do all the hard work of isolating individual date elements for you.

Time of day, the friendly version Want to include the time of day? Use getTime(): At the tone, it’s

<script language=”JavaScript”>

document.writeln(rightNow.getHours() +”:”+ rightNow.getMinutes());

</script>

exactly.

Typical output for this code might look like the following: At the tone, it’s 20:12 exactly.

Locale-specific date and time You might not think of locale as the collection of all standard information that defines how your part of the world specifies numeric values, dates, time, and many other things, but that’s exactly how computers think of it. So the method toLocaleString() proves tremen­ dously helpful. The following code produces a helpful (and amusing) result: <div style=’font-size:75%;color:#333’>

Page last modified

<script language=”JavaScript”>

document.writeln(rightNow.toLocaleString());

</script>

</div>


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.