Introduction
This tutorial is designed to provide you with an understanding of the Java Calendar class, it’s backgrounds, purpose and uses. It is created in such a manner as to allow even beginning Java programmers an understanding and feel for the uses of the Java Calendar class. The Java Calendar class was added to the Java Development Kit in JDK 1.1. It is designed to permit the conversion between a specific instance in time and a set of Calendar fields. (Oracle, 2004, 2010) What exactly does this mean? The Calendar class uses a huge array of tables to keep track of time based on daylight savings time, timezones, and calendar history, the calendar class uses a system time to determine where whatever event is being tracked falls on in the internal calendar tables. Some confusion is caused by this as Java does keep track of specific location time, and the programmer needs to keep this in mind when using the Calendar class even when it isn’t relevant to the problem being addressed (Roedy Green, Canadian Mind Products, 1196-2011).
How to use the Calendar Class
The Calendar Class and it’s associated methods are used by three methods. The programmer can import the calendar class and whatever specific method or constructor they will use in their program by importing it as importjava.util.specificfunction;
The Essay on First Class Painters Time Hotels
Many people devote () their lives travelling. They can spend a lot of time for the road. And they can travel by car, by sea, by train, and by air. Also travelling by air usually preferred by people who haven't got much time and they must quickly get to another city, country or continent. Nowadays there are a lot of businessmen who have to communicate with people from other countries. Each of us ...
For instance, if the programmer wished to set the date within a program, but that was all that was needed, for instance no date specific math was needed as in a log file, then the programmer could use, importjava.util.Calendar.set;
If the programmer needs to have greater functionality associated with the dates being used within a program the programmer should use the entire Calendar class. This takes up more space within a program, however provides a much simpler method of calling items from the Java Calendar class as all of it’s functionality is available to the entire program. This format would simply be, importjava.util.Calendar;
Finally the programmer can call within the program any specific function required within the Calendar class by using a fully qualified name for the method being used, if the programmer wished to use the set function once within a program and that was all that was needed the programmer could simply use public void java.util.Calendar.set
For ease of use of associated Java Calendar methods and constructs however it is generally recommended that the programmer use the import function and import the entire Calendar class. This provides for significantly less time coding, and less possibility of mistakes in typing out commands and code as less code is necessary.
Melissa Robinsons Section
Every so often a program wishes to know something about a date, such as what day of the week something took place or maybe you would like to know which of the 12 months have 30 days. This can be completed with the Calendar class within the java.util package. The very first thing that should be done is to import the package: import java.util.Calendar;
The next thing to do is to get an instance of the Calendar class: Calendar cal = Calendar.getInstance( ); Be aware that the constructor cannot directly be called upon with new Calendar( );, since it’s an abstract class. The next thing to do is set the date and time of what is wanted to know about certain things: cal.set(year,month,day);
For the month parameter, January is 0, February is 1, March is 2, etc. The constants Calendar.MONTH can also be used. Each and every calendar has a set of boundaries that are automatically updated when the calendar is altered. The get ( ) method can access these and a set of constants that characterize a number of available fields. So it can be noted that some very precise things can be done with the calendar now. For example, the week of the year that a day falls on can be found by using: int week = cal.get(Calendar.WEEK_OF_YEAR)
The Essay on Mayan Astronomy Calendar Babylonian Day
Babylonian – Mayan Astronomy Babylonian – Mayan Astronomy Essay, Research Paper Mayan Astronomy was better Than Babylonian Astronomy Mayan astronomy differed in several ways compared to Babylonian astronomy. Among the numerous ways were their different beliefs in the heavens, space, planets Earth and even their calendars. The Mayan calendar is one of the world? s most ancient calendar systems. ...
Or For example. Use the getActualMaximum() to find the number of days in a certain month: intdaysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); Here are some fields that may be useful within the Calendar Class: * DAY_OF_WEEK – Returns the day of the week that a day falls on, 1 through 7 days. * DAY_OF_YEAR – Returns the number of days into the year that the date occurs * WEEK_OF_MONTH – Returns the week number in the current month where the date occurs * DAY_OF_MONTH – Returns the current day of the month
Andrew McCutchan’s Section
Examples of Calendar Class Use:
Below are some typical examples of the usage of the java calendar class. /* Java Calendar
Follow along with this example in a text editor to have java show todays date and time. */
import java.util.Calendar;
public class JavaCalendar {
public static void main (string[] args) {
Calendar cal = Calendar.getInstance() ;
System.out.println(“Today is : ” + cal.getTime() ) ;
By following the formats for cal.get instances mentioned above, one can find the various dates, times, weeks, and months in current formats, or in predetermined periods. This method allows programmers to set specific time constraints when coding for specific results.
End of Section
Methods Within the Calendar Class
There are many methods within the calendar class. Methods are used for querying, setting, and doing arithmetic on the various fields of the date and time. The most commonly used methods are: * add( )
* set( )
* roll( )
References
1. Oracle. (2004, 2010).
java.util Class Calendar. Retrieved from http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html#set(int, int) 2. Roedy Green, Canadian Mind Products. (1196-2011).
The Essay on 260 Day Maya Calendar Days
The Maya Calendar The Maya calendar in its final form probably dates from about the 1 st century B. C. It is extremely accurate, and the calculations of Maya priests were so precise that their calendar correction is 10, 000 th of a day more exact than the standard calendar we use today. They used 20-day months, and had two calendar years: the 260-day Sacred Round, or tzolkin, and the 365-day Vague ...
Calendar : Java Glossary. Retrieved from http://mindprod.com/jgloss/calendar.html