Basic HTML version of Foils prepared Sept 21 1998

Foil 20 The Date class

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken


This class provides an implementation of "date" structures. Date has methods to create and compare dates, obtain and set the time, and convert dates to strings.
The Date constructor creates today's date:
  • Date today = new Date();
In Java 1.1, most Date methods have been deprecated in favor of the Calendar class:
  • Calendar date1 = Calendar.getInstance();
  • date1.set( 999, 12, 31 ); /* Dec. 31, 999 */
  • Calendar date2 = Calendar.getInstance();
  • date2.set( 1996, 12, 31, 23, 59, 59 )
    • /* Dec.31,1996 at 23:59:59 */



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998