Accessibility
 
Home > Products > UltraDev > Support > Building Common Applications
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Building Common Applications
Using date-related Java classes

Java has several classes to let you work with dates and times. One is the Date class, which defines a particular instant in time to the nearest millisecond, measured from January 1, 1970. Another class is the GregorianCalendar class, which provides you with more flexibility in terms of displaying dates and times.

After deciding to use the GregorianCalendar class to take advantage of its formatting flexibility, you address the next question: How do I refer to this class in my scriplets?

A JSP-compliant application server automatically provides you with a number of Java objects to use on a JSP page (for example, the session object), but the GregorianCalendar object is not one of them. As a result, you must import the GregorianCalendar class from the standard Java class library by entering the following page directive at the top of the page:

<%@page import="java.util.GregorianCalendar"%>

This directive adds the GregorianCalendar class to the list of Java classes available to you on the page.

Note: The GregorianCalendar class is part of the java.util package (all Java classes are bundled in packages). If you select Java as your scripting language, the page automatically imports every class in the following four packages: java.lang, javax.servlet, javax.servlet.http, and javax.servlet.jsp.

If you omit this page directive, you can still use the GregorianCalendar class, but you'll always have to refer to it explicitly as java.util.GregorianCalendar in your scriptlets. This can make the code harder to write and read.

To Table of Contents Back to Previous document Forward to next document