Date and SimpleDateFormat
1 2 /*3 date Day Class Many methods have been replaced by the calendar4 date () Gets the highest current time usage probability5 Calendar class using constants to get the current time is generally seldom used6 7 the SimpleDateFormat class formats the time format method8 9 String string converted into time to take advantage of the Parse methodTen */ One Public Static voidMain (string[] args) { ACalendar calendar = Calendar.getinstance ();//gets the current system time, instead of the date acquisition time - //foreign set Month is zero-based, so you have to add a -System.out.println (Calendar.get (calendar.year) + "year" + (Calendar.get (calendar.month) + 1) + "Month" +calendar.get ( Calendar.date));//Month Day Time the - //Calculate time Division seconds -System.out.println ("When:" +Calendar.get (Calendar.hour_of_day)); -System.out.println ("min:" +Calendar.get (Calendar.minute)); +System.out.println ("Seconds" +Calendar.get (Calendar.second)); - + A /* at SimpleDateFormat class to format time - role 1: The date can be converted to the specified format of the string format () - role 2: You can convert a character to the corresponding date parse () - */ -Date Date =NewDate (); -SimpleDateFormat DateFormat =NewSimpleDateFormat ();//default constructor method, no format specified in System.out.println (Dateformat.format (date)); - to //the date after formatting +SimpleDateFormat DATEFORMAT2 =NewSimpleDateFormat ("yyyy mm month DD Day HH:MM:SS"); - System.out.println (Dateformat2.format (date)); the *SimpleDateFormat DATEFORMAT3 =NewSimpleDateFormat ("yyyy mm month DD Day"); $String birthday = "November 1, 2000";Panax Notoginseng Try { - //This string format should be consistent with the format in DateFormat theDate Date2 =dateformat3.parse (birthday); + System.out.println (date2); A}Catch(ParseException e) { the //TODO auto-generated Catch block + e.printstacktrace (); - } $ $ -}
Math class
1 /*2 the Math class is a mathematical formula class3 ABS (double A) is an absolute class4 ceil (double A) rounding up5 Floor (double A) rounding down6 round () rounding7 random () number 0-1 can be rounded by multiples8 of course, you can also use the random class9 Ten One */ A Public Static voidMain (string[] args) { - - intA =-1; the System.out.println (Math.Abs (a)); - - floatb = 3.14f;//the value is big! - floatc = -3.14f;//the value is big! + System.out.println (Math.ceil (b)); - System.out.println (Math.ceil (c)); + A System.out.println (Math.floor (b)); at System.out.println (Math.floor (c)); - -System.out.println ("Rounding:" + Math.Round (3.53)); - - System.out.println (Math.random ()); - inRandom random =NewRandom ();//generate 0-10 is a random number - intran = Random.nextint (10) +1;//is greater than a to System.err.println (ran); + - the *}
Date Math SimpleDateFormat Class