5. Dates and TimesMost Java programs have to deal with dates and times at one point or another. Fortunately, Java has good built-in support for working with dates and times. Three primary classes are used in most Java programs to store and manipulate times and dates. Those classes are the java.util.Date class, the java.sql.Date class, and the java.util.Calendar class. Many of the methods in the java.util.Date class have become deprecated, meaning that you should avoid using them in new development. The deprecated methods generally deal with the creation and manipulation of dates. For these operations, the java.util.Calendar class is the preferred mechanism to use. It is also easy to convert between Date and Calendar objects, so if you prefer to pass your dates around as Date objects, you can still avoid using the deprecated methods. You would simply convert the dates to Calendar objects when it's time to manipulate the dates. A phrase in this chapter shows you how to convert between Date and Calendar objects. |