CSDateTime is a Java Servlet that prints out the current date and/or time in a variety of formats. The servlet is useful for embedding that information in a web page using server-side includes.
Features
Installation
This program requires a web server that has servlet support. Such web servers include Java Web Server by Sun, Netscape Enterprise Server, and versions of Apache. If you are not sure whether your web server has servlet support, contact your System Administrator. Various external servlet engines are also available. Of those, the servlet has been specifically tested with JRun. More information about servlet environments is at http://www.coolservlets.com.
Copying The Servlet
You need to copy CSDateTime.class into the servlet directory on
your web server. This is often
servlets/. You may need to restart your servlet engine depending on your
environment. After that, the servlet should be fully functional.
Usage
Look in the demo directory of this distribution for sample uses of the servlet.
The normal use of this servlet is with Server-Side Includes (SSI). For a full description of SSI and its use with Servlets, consult your servlet engine or web server documentation.
Calling CSDateTime servlet with no parameters will result in text output like the following:
March 21,1999The matching SSI command would be:
<SERVLET CODE="CSDateTime"> </SERVLET>To print other formats for the date and time, you must provide a formparameterter to the servlet. Such an SSI command might look like the following:
<SERVLET CODE=CSDateTime>The servlet interprets the format command and then builds the date and time output based on the tokens it finds. A summary of these tokens and their meanings is in a table below.
<PARAM name="format" value="MMM - yy - HHHH">
</SERVLET>
| Pattern Letter | Meaning | Examples Pattern -- Result |
| d | Day in month (N) | d -- 7 dd -- 07 |
| D | Day in year (N) | D -- 89 |
| F | Day of week in month (N) | F -- 2 |
| E | Day in week (T) | E -- Tues EEE -- Tues EEEE -- Tuesday |
| w | Week in year (N) | w -- 15 |
| W | Week in month (N) | W -- 2 |
| M | Month in year (T or N) | MM -- 09 MMM -- Jul MMMM -- July |
| y | Year (N) | yy -- 97 yyyy -- 1997 |
| G | Era designator (T) | G -- AD |
| K | Hour in AM/PM [0-11] (N) | K -- 0 |
| h | Hour in AM/PM [1-12] (N) | h -- 12 |
| k | Hour in day [1-24] (N) | k -- 24 |
| H | Hour in day [0-23] (N) | H -- 0 |
| m | Minute in hour (N) | m -- 45 |
| s | Second in minute (N) | s -- 14 |
| S | Millisecond (N) | S -- 583 |
| a | AM/PM Marker (T) | a -- PM |
| z | Time zone (T) | z -- CST zzzz -- Central Standard Time |
<SERVLET CODE=CSDateTime>A summary of valid time zones is below (you should supply the servlet with the ID):
<PARAM name="timeZone" value="PST">
</SERVLET>
| ID | Name | Offset |
| MIT | Midway Islands Time | -11 |
| HST | Hawaii Standard Time | -10 |
| AST | Alaska Standard Time | -9 |
| PST | Pacific Standard Time | -8 |
| PNT | Phoenix Standard Time | -7 |
| MST | Mountain Standard Time | -7 |
| CST | Central Standard Time | -6 |
| EST | Eastern Standard Time | -5 |
| IET | Indiana Eastern Standard Time | -5 |
| PRT | -4 | |
| CNT | Canada Newfoundland Time | -3.5 |
| AGT | Argentina Standard Time | -3 |
| BET | Brazil Eastern Time | -3 |
| CAT | Central African Time | -1 |
| GMT | Greenwich Mean Time | 0 |
| ECT | European Central Time | 1 |
| EET | Eastern European Time | 1 |
| ART | (Arabic) Egypt Standard Time | 2 |
| EAT | Eastern African Time | 3 |
| MET | Middle East Time | 3.5 |
| NET | Near East Time | 4 |
| PLT | Pakistan Lahore Time | 5 |
| IST | India Standard Time | 5.5 |
| BST | Bangladesh Standard Time | 6 |
| VST | Vietnam Standard Time | 7 |
| CTT | China Standard Time | 8 |
| JST | Japan Standard Time | 9 |
| ACT | Australia Central Time | 9.5 |
| AET | Australia Eastern Time | 10 |
| SST | Solomon Standard Time | 11 |
| NST | New Zealand Standard Time | 12 |
We have made every effort to make this servlet easy to install and as robust as possible. If you are having problems making it work, first go back over the installation instructions and make sure you followed them exactly. If that does not fix the problem, verify that servlets are working correctly on your web server. Additional help can be found on http://www.coolservlets.com where FAQ's or discussion forums may exist for this servlet.
Bugs in the servlet can be reported to bugs@coolservlets.com. You may also send descriptions of any other problems you are having with the servlet to that address, but we canguaranteentee a reply due to our busy schedules.
If you require technical support, please see below for information about how to purchase it.
Source
The full source of the servlet be found in the src
folder in this distribution. If you would like compile it, you'll need the Servlet SDK which is available
on the Java website: http://java.sun.com .
Technical Support
Individuals or companies that would like technical support for this servlet can buy unlimited email tech support for $50. A support contract can also be purchased for $150 which provides unlimited email tech support for all CoolServlets.com servlets. Please see http://www.coolservlets.com/support for further details.
Purchasing technical support guarantees a quick resolution to any problems you have with CoolServlets.com
servlets. It is also a great way to aid the continued development of further high quality, free, open-source
servlets.
License
This servlet is distributed under the GNU Public License. This means that the program is completely free (see below for legalese).
However, there are
a few voluntary things that we would really appreciate: provide links back to CoolServlets.com instead
of redistributing the code (this wguaranteentee that people will always be able to get the
latest version), and send us bug reports or feature requests. Also, we encourage you
to put the CoolServlets.com button somewhere on your site so that other people can find out about our
free servlets. Please spread the word about CoolServlets.com!
Copyright (C) 1999 Matt Tucker and Bill Lynch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA