JavaScript
  Home arrow JavaScript arrow Page 2 - Useful Web Widgets
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Useful Web Widgets
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-01-18

    Table of Contents:
  • Useful Web Widgets
  • Getting Down With Father Time
  • The Function in Depth
  • A Calendar Engine
  • The Interface Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Useful Web Widgets - Getting Down With Father Time


    (Page 2 of 5 )

    Keeping track of time and things that require time is pretty important for people these days. Even visitors to your site that have a watch on their wrist may find it valuable to see the time and date displayed somewhere on your pages. JavaScript has quite a few functions that deal with dates and times but their output is not always what you may need for display. The next script uses the built in JavaScript date and time functions to produce a displayable date and time in any format you want.

    This function uses a specially formatted string to determine what format to display. The rules are pretty simple. Below is a sample string.

                "ts,dl,l"

    The string has a comma separated structure with two sections of two letters each and a single section of one character. The first character in the two character sections can be either a "t" or "d". The "t" stands for "text" and indicates that the month or day will be expressed in text. The "d" stands for "digit" and will render the month or day as a digit. The second character in the two character sections can be either an "s" or "l". The "s" stands for short which would mean that the short form of the value would be displayed such as "Aug" or "Wed". The "l" stands for "long" and would render a long version of the month or day such as "August" or "Wednesday" The single character section can contain either a "s" or an "l" to render either a short or long version of the year (06 or 2006).

    Given this, the sort of date we could derive from the above example would look like this.

                Jan 01 2006

    The month is text and in short form and the day is exclusively in digits in long form (leading zero). The year is displayed in long form as well. The format we are working with here is standard US month, day, year. The function could be reworked for other date formats as well.

    If the day is specified to be text in long form, it is rendered in both digit form and text as follows.

                Sunday Jan 01 2006

    By using this method you can display many formats under script control.

    More JavaScript Articles
    More By Chris Root


       · Thank you for reading the article. Comments are welcome.
     

    JAVASCRIPT ARTICLES

    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT