Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 
Javascript story on date making.
javascript story search bar.
Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format


Tips on using javascript.
Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 

JavaScript Tip:
Make A Date With JavaScript

by Larisa Thomason,
Senior Web Analyst,
NetMechanic, Inc.

  
June 2002 (Part 2)
Vol. 5, No. 12
 • Promotion Tip
 • CSS Tip
 • JavaScript Tip
  

JavaScript is a handy, low-impact way to add interactivity to Web sites. One of its coolest features is the ability to manipulate dates. We'll show you a couple of simple date-handling scripts that make your page seem more current and useful to visitors.

JavaScript Date And Time Rules

The JavaScript DATE object controls both dates and times. You can use it to format dates, create new date objects, and perform calculations. The DATE object doesn't have any properties and you'll have to create a new one each time you need to store a date.

Create a new DATE object using the NEW keyword:

Today = new Date();
Anniversary = new Date("March 21, 1992")

"Today" stores the current date because you haven't defined any parameters, while "Anniversary" stores a date you provide.

Read a more complete discussion of the DATE object - and see another cool script - in our Javascript Story - Generate Excitement With A Countdown JavaScript tip.

Now let's try a simple script that uses the DATE object.

Today's Date Is…

This script displays the current date on your Web page and formats it as "Month date, year" (like January 1, 2002).

Include this code in your page's HEAD section:

This sets up arrays with the actual days of the week and month names and defines a function called printDate(). Refer to the function in the BODY section of your document wherever you'd like to include the date:

<p>
<SCRIPT LANGUAGE="JAVASCRIPT">printDate()</SCRIPT>
</p>

We've used it here:

Get Fresh With Visitors

Visitors want to know that they're getting up-to-date, reliable content from a Web site. They can use a bookmarklet to check page freshness, but why force them to? If you haven't updated your page since disco was popular (the first time), then just admit it to your visitors.

This little script doesn't use the DATE object, but we're including it because it is date-related and some subscribers have asked how to do it. Insert this code into the BODY section of your document wherever on the page you'd like it.

You can include HTML code inside your document.write statement if you want the last updated message to display in bold or in a different color than the surrounding content. Be careful: it's easy to make mistakes when you do that, so consider using style sheets instead.

On this page, we created a special class called "update" and applied that class to the paragraph containing the code.

Place this in the HEAD section:

<style type="text/css">
.update
{
color:red;
font-weight:bold;
}
</style>

And in the BODY section:

<p class="update">insert the JS code from above here</p>

Here's how it looks on this page:

More About JavaScript

You can do a lot more complicated calculations with JavaScript dates than what we've shown you in this story.

If you'd like more information and access to other JavaScript techniques, check out these resources:

There are a lot of other JavaScript resources available too, but browse through these to get an idea of just how useful JavaScript can be.

But don't get so taken with stunning JavaScript and DHTML effects that you forget site usability and accessibility issues. Remember that many people surf with JavaScript turned off in their browsers - often trying to avoid annoying pop-up windows - and visitors who are using assistive technologies may not have JavaScript-capable browsers at all.

If you're considering using JavaScript to display really important site information, do this simple test first. Turn JavaScript off in your browser and see how the page looks and works. You may find that your navigation system has shut down, special offer pop-ups don't appear, or other unexpected problems.

And always remember that JavaScript isn't the only culprit when we're discussing page display problems. Even a simple HTML coding error like a misplaced INPUT tag can break your page completely in one browser even though it looks great in others.

Check your pages with NetMechanic's HTML Toolbox. It scans your site and identifies browser-specific code, slow-loading pages, broken pages, and HTML code errors. Best of all, Toolbox will repair your page and give you a corrected file that you can upload to your site.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.