Wednesday, July 17, 2019

Java Calendar Tutorial Essay

accessThis tutorial is designed to provide you with an concord of the coffee schedule physique, its backgrounds, take aim and works. It is created in such a means as to all in allow til now origination Java softw atomic number 18 engineers an understanding and feel for the applys of the Java Calendar enlighten. The Java Calendar configuration was added to the Java Development Kit in JDK 1.1. It is designed to permit the conversion amongst a specialized type put upters case in cadence and a sight of Calendar fields. (Oracle, 2004, 2010) What exactly does this mean? The Calendar class exercises a huge array of tables to occur track of time based on solar mean solar twenty-four hourslight savings time, timezones, and schedule history, the schedule class intents a system time to determine where whatever event is world tracked waterfall on in the internal calendar tables. Some sloppiness is caused by this as Java does hold back track of special(prenominal) l ocation time, and the political write in coder needs to keep this in intelligence when using the Calendar class even when it isnt relevant to the problem macrocosm addressed (Roedy Green, Canadian look Products, 1196-2011).How to use the Calendar course of studyThe Calendar segmentation and its associated methods are used by three methods. The programmer can importing the calendar class and whatever specific method or constructor they pull up stakes use in their program by importing it as importjava.util.specific junctureFor instance, if the programmer wished to set the fitting at bottom a program, except that was all that was needed, for instance no particular date specific math was needed as in a log file, and so the programmer could use, importjava.util.Calendar.setIf the programmer needs to thrust greater functionality associated with the dates being used within a program the programmer should use the complete Calendar class. This takes up to a greater extent space within a program, withal provides a much simpler method of occupational group items from the Java Calendar class as all of its functionality is available to the entire program. This format would simply be, importjava.util.CalendarFinally the programmer can call within the program any specific function unavoidable within the Calendar class by using a fully adapted name for the method being used, if the programmer wished to use the set function formerly within a program and that was all that was needed the programmer could simply use public void java.util.Calendar.setFor ease of use of associated Java Calendar methods and constructs however it is broadly speaking recommended that the programmer use the import function and import the entire Calendar class. This provides for significantly less time coding, and less initiative of mistakes in typing out commands and code as less code is necessary.genus Melissa Robinsons SectionEin truth so frequently a program wishes to kno w several(prenominal)thing slightly a date, such as what day of the hebdomad some(a)thing took place or maybe you would like to know which of the 12 calendar months bear 30 days. This can be realised with the Calendar class within the java.util package. The very first thing that should be do is to import the package import java.util.CalendarThe adjacent thing to do is to micturate 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 nigh thing to do is set the date and time of what is wanted to know active authorized 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. distributively 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 con stants that characterize a go of available fields. So it can be noted that some very particular things can be done with the calendar now. For example, the hebdomad of the year that a day falls on can be found by using int week = cal.get(Calendar.WEEK_OF_YEAR)OrFor example. Use the getActualMaximum() to find the design of days in acertain month intdaysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH) Here are some fields that may be useful within the Calendar level * DAY_OF_WEEK Returns the day of the week that a day falls on, 1 through 7 days. * DAY_OF_YEAR Returns the outlet 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 monthAndrew McCutchans SectionExamples of Calendar Class UseBelow are some typical examples of the usage of the java calendar class. /* Java CalendarFollow on with this example in a text editor to have java show todays date an d time. */import java.util.Calendarpublic class JavaCalendar public static void main(prenominal) (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 miscellaneous 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. stamp out of SectionMethods Within the Calendar ClassThere are many methods within the calendar class. Methods are used for querying, setting, and doing arithmetical on the various fields of the date and time. The most commonly 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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.