Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
May 5, 1999

Setting Dates With Calendar and GregorianCalendar

In Java 1.0.2, the java.util.Date class was used to represent a point in time, as well as to parse and format date values. However, as part of the internationalization features introduced with Java 1.1, most of the methods in Date were deprecated, and the java.util.Calendar and java.util.GregorianCalendar classes were added. Calendar is an abstract class and cannot be instantiated, while GregorianCalendar is a concrete subclass of Calendar that's often useful when working with date and/or time values. There are a number of GregorianCalendar constructors that you can use when creating date/time representations. For example, to create an instance that corresponds to July 4, 1776, use:
 
GregorianCalendar grc =
new GregorianCalendar(1776, Calendar.JULY, 4);
You can also create an instance that includes a specific time value, such as 12:34:56 as follows:
 
GregorianCalendar grc =
new GregorianCalendar(1776, Calendar.JULY, 4, 12, 34, 56);
The Calendar and GregorianCalendar classes provide many useful methods for such functions as date arithmetic, identifying leap years, and so forth.
Brett Spell
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date