Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

java.util.Calendar

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 MethodMeaning
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).

Example

See Example - Text Clock.

References

Sun has never gotten the Date class right, even 10 years after the first release. Take a look at weblogs.java.net/blog/mister__m/archive/2006/02/tiger_and_dates.html.

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.