Date class:
1Date Date =NewDate ();//gets the current system time2System.out.println ("Year:" +date.getyear ());3 4Calendar calendar = Calendar.getinstance ();//gets the current system time. 5System.out.println ("Year:" +Calendar.get (calendar.year));6System.out.println ("Month:" + (Calendar.get (calendar.month) +1));7System.out.println ("Day:" +Calendar.get (calendar.date));8 9System.out.println ("When:" +Calendar.get (Calendar.hour_of_day));TenSystem.out.println ("min:" +Calendar.get (Calendar.minute)); OneSystem.out.println ("seconds:" + calendar.get (Calendar.second));
Date formatting classes:
1 /*date formatting class SimpleDateFormat2 * Role 1: Can convert the date to the specified format string format ()3 * Function 2: You can convert a character to the corresponding date. Parse ()4 */5Date Date =NewDate ();//gets the current system time. 6SimpleDateFormat DateFormat =NewSimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");//A date formatting object was created using the default format. 7String time = Dateformat.format (date);//you can convert a date to a string in the specified format8SYSTEM.OUT.PRINTLN ("Current system time:" +Time );9 TenString birthday = "December 26, 2000 11:29:08"; OneDate date2 = Dateformat.parse (birthday);//Note: The specified string format must be consistent with the SimpleDateFormat pattern. ASystem.out.println (DATE2);
Date class and date formatting classes for Java