More about Java Man

java woman

"Java man" skullcap
 

Marjolein's Date and Time

We're moving!

This whole site is being moved to a shiny new server - as are all my sites, in fact. Apologies for the bumpy road ahead, but at the end of that road things will become fast and smooth.

Once the site at the new server is ready, this message will automatically disappear!

Meanwhile, you can see how the move is progressing at the status page.

  Contents
Quick search:

Symbols used:

About this page
DateTime applet
DateApplet applet
Free download
Feedback
 
 
  About this page

Here's a demo of a few applets using my first class.

Both applets use the class StringDateTime to display the current date and time. StringDateTime extends the Date class; it can output the current date and time (or its elements) in string form. This class accepts various arguments for formatting, such as whether or not a century is displayed, the order in which year, month and day appear, and a separator for displaying a date. For displaying the time, there's a similar set of arguments.

 
top
 
 
  DateTime applet

The applet below is called DateTime and it interactively shows some of the arguments the StringDateTime class accepts for formatting date and time.

(DateTime applet)

The DateTime applet uses a number of on-screen controls to set most of the arguments for StringDateTime, and the result is immediately visible in the colored panel below the controls. Go ahead and click around, and see what happens!
The applet uses a separate thread to keep the clock 'ticking', even while you change the parameters.

Its main purpose is to show the effect of the various parameters accepted by the StringDateTime class, which is also used by the more useful Dateapplet applet shown below

 
top
 

  DateApplet applet

The DateApplet has two different functions demonstrated below: it can either show the current date or the current time, depending on the parameters specified.


 

(Current date)

To the left, a second applet called DateApplet displays the current date. This applet accepts several parameters from the HTML source through the <PARAM> attributes of the <APPLET> tag; some of these parameters are then passed as arguments to the StringDateTime class, and a few extra to control the appearance. The most important parameter is called displaytype: it controls whether a date or a time is displayed. Of course it's set to 'date' here, and only parameters for the appearance of a date are passed. (The other parameters would be ignored, anyway!)

As with the DateTime applet above, a separate thread takes care of keeping the clock 'running'.


  (Current time)

Here's a second example of the same DateApplet applet: now displaytype is set to 'time' instead of 'date'. Of course, this time parameters for controlling the appearance of the time are passed, like the separator, the fact that seconds should be shown, and that it should appear in 24-hour format.

Note: I have found that on a Windows platform the time shown may be off one hour; this can occur when Windows is set to automatically correct for daylight savings time. I suspect this automatic correction is really like a 'layer' over the actual system time which is still picked up by Java. If you adjust manually for daylight savings time (actually resetting the system clock) or use an Internet application to regularly reset your system clock from a time server, the time shown is correct.

 
top
 
 
  Free download

You can download the DateTime and DateApplet classes (for the applets), the StringDateTime class, and all sources, from the Date & Time download page. Before you go there: Save the source of this page for documentation on the usage of DateApplet: it's in a comment block just above where the applet is used.

 
top
 
 

Feedback

If you have any problems with these applets, or have other comments,