Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Java Date, Calendar and Time API - Tutorial

Lars Vogel

Version 0.3

26.03.2010

Revision History
Revision 0.101.05.2009Lars Vogel
First Version
Revision 0.205.02.2010Lars Vogel
Typo fixed
Revision 0.326.03.2010Lars Vogel
how to format the output format of date

Java Date and Time API

This article explains the API for using Calendar, Date and Time in Java and how to format the output of a date.


Table of Contents

1. Overview
2. Format date
3. Working with Dates and Calendars
3.1. Calendar
3.2. Date and Date Conversion
4. Thank you
5. Questions and Discussion
6. Links and Literature

1. Overview

The Java language provides direct support for time based objects. This article gives a few examples how this API can be used. .

The class java.util.Date was the first implementation which was used for manipulating dates. The class java.util.Calendar was added in Java 1.1 and provides simplified access to storing and manipulating dates.

It is recommended to use Calendar if possible. In reality you have to convert frequently from Date to Calendar and vice versa, e.g. during database access you often get a java.sql.Date object. The following explains how to use Calendar and how to convert Dates into Calendar.