Thursday, March 7, 2019
Java Calendar Tutorial Essay
IntroductionThis tutorial is designed to provide you with an understanding of the burnt umber schedule kind, its 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 schedule mannikin. The Java calendar class was added to the Java Development fit in JDK 1.1. It is designed to permit the conversion between a particular instance in era and a set of schedule fields. (Oracle, 2004, 2010) What incisively does this mean? The schedule class uses a huge array of tables to give track of clipping based on daylight savings time, timezones, and calendar history, the calendar class uses a system time to determine where any(prenominal) event is creation tracked falls on in the home(a) calendar tables. Some confusion is cause by this as Java does give track of specific location time, and the programmer needs to keep this in mind when using the calendar class even when it isnt ge rmane(predicate) to the problem existence addressed (Roedy Green, Canadian Mind Products, 1196-2011).How to use the Calendar phaseThe Calendar shed light on and its associated methods argon used by three methods. The programmer butt end import the calendar class and any(prenominal) specific method or constructor they will use in their program by importing it as importjava.util.specificfunctionFor instance, if the programmer wished to set the season within a program, but that was all that was needed, for instance no picture specific math was needed as in a pound file, then the programmer could use, importjava.util.Calendar.setIf the programmer needs to have greater functionality associated with the dates being used within a program the programmer should use the unblemished Calendar class. This takes up more space within a program, provided provides a much simpler method of calling items from the Java Calendar class as all of its functionality is easy to the entire program. This format would scarce be, importjava.util.CalendarFinally the programmer dejection 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 unrestricted void java.util.Calendar.setFor ease of use of associated Java Calendar methods and constructs however it is more often than not 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 type out commands and code as less code is necessary.Melissa Robinsons pieceEvery so often a program wishes to know just aboutthing intimately a date, such as what day of the week something took place or maybe you would like to know which of the 12 calendar months have 30 eld. This can be completed with the Calendar class within the java.util package. The very archetypical thing that should be done is to import the package import java.util.CalendarThe beside 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 its 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, and so on 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 exit of available fields. So it can be noted that some very nice 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.ge t(Calendar.WEEK_OF_YEAR)OrFor example. Use the getActualMaximum() to find the number of days in acertain 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 finished 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 authentic month where the date occurs * DAY_OF_MONTH Returns the current day of the monthAndrew McCutchans SectionExamples of Calendar Class UseBelow are some typical examples of the usage of the java calendar class. /* Java CalendarFollow along with this example in a text editor program to have java show todays date and time. */import java.util.Calendarpublic 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 insta nces 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 SectionMethods Within the Calendar ClassThere 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 normally used methods are * add( )* set( )* roll( )References1. Oracle. (2004, 2010). java.util Class Calendar. Retrieved from http//download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.htmlset(int, int) 2. Roedy Green, Canadian Mind Products. (1196-2011). Calendar Java Glossary. Retrieved from http//mindprod.com/jgloss/calendar.html
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment