Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java: java.util.Calendar

JavaFAQ Home » Java Notes by Fred Swartz Go to all tips in Java Notes by Fred Swartz

Bookmark and Share The java.util.Calendar class is used to represent the date and time. The year, month, day, hour, minute, second, and milliseconds can all be set or obtained from a Calendar object. The default Calendar object has the current time in it. There are also methods for making data calculations.

Other related classes: Date, and DateFormat, ...

To get the current time

The default Calendar constructor produces an object whose fields are set to the current time for the default timezone and locale.
Calendar now = Calendar.getInstance();

Getting the value of the fields

The following field names can be used as an argument to the Calendar.get(. . .) method. In all of these examples, t is a Calendar object.
Access Method Meaning
t.get(Calendar.YEAR) int value of the year
t.get(Calendar.MONTH) int value of the month (0-11)
t.get(Calendar.DAY_OF_MONTH) int value of the day of the month (1-31)
t.get(Calendar.DAY_OF_WEEK) int value of the day of the week (0-6)
t.get(Calendar.HOUR) int value of the hour in 12 hour notation (0-12)
t.get(Calendar.AM_PM) returns either Calendar.AM or Calendar.PM
t.get(Calendar.HOUR_OF_DAY) int value of the hour of the day in 24-hour notation (0-24)
t.get(Calendar.MINUTE) int value of the minute in the hour (0-59)
t.get(Calendar.SECOND) int value of the second within the minute (0-59).
t.get(Calendar.MILLISECOND) int value of the milliseconds within a second (0-999).


See Example - Text Clock.
 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy