Gets the specified date information in the date such as get year, month, day
1 Packagecn.itcast.api.a.date;2 3 ImportJava.util.Calendar;4 5 Public classDateDemo2 {6 7 /**8 * @paramargs9 */Ten Public Static voidMain (string[] args) { One A //Requirement 2: Based on requirement 1, gets the date and time of the string information (local). - //How do I get the date information specified in the string? For example to get years, and to judge. - //1, gets the date object. Date the //Date date = new Date (); - - //jdk1.1 begins the Calendar. //gets the Calendar object. -Calendar C = calendar.getinstance ();// + - intYear =C.get (calendar.year); + intmonth = C.get (calendar.month) +1; A intDay =C.get (calendar.day_of_month); atString week =Getcnweek (C.get (Calendar.day_of_week)); - - //Information about the date and year of the printed information is here. Gets the value of the specified field Oh, yes. -SYSTEM.OUT.PRINTLN (year+ "year" +month+ "month" +day+ "Day" +week); - - } in //Let the week field correspond to the Chinese week. Tabular Array. - to Public StaticString Getcnweek (inti) { + if(i<0 | | i>7){ - Throw NewRuntimeException (i+ "no corresponding Week"); the } * //define the table. $String[] weeks = {"", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};Panax Notoginseng - returnWeeks[i]; the } + A the + - $ $ -}
2, other class API------Calendar