Record some time common operations
Public classDateca { Public Static voidMain (string[] args)throwsParseException {/**time operation the calendar Gregorian calendar **/Calendar CA=calendar.getinstance (); //get a single attribute for a date: year, month, week, day, time, minuteSystem.out.println (Ca.get (calendar.year)); System.out.println (Ca.get (Calendar.month));//get month starting from 0System.out.println (Ca.get (calendar.week_of_year)); System.out.println (Ca.get (calendar.day_of_month)); System.out.println (Ca.get (calendar.hour_of_day)); System.out.println (Ca.get (Calendar.minute)); //Date OperationCa.add (Calendar.year, 2);//two years back .System.out.println (Ca.get (calendar.year)); Ca.add (Calendar.month,2);//two months back .System.out.println (Ca.get (calendar.month)); Ca.add (Calendar.day_of_month,10);//two days back .System.out.println (Ca.get (calendar.day_of_month)); //set the required time directlyCa.set (calendar.year,100);//sets the given Calendar field to the given value. System.out.println (Ca.get (calendar.year)); Ca.set (2018, 7, 12); System.out.println (Ca.get (calendar.year)); System.out.println (Ca.get (calendar.month)); System.out.println (Ca.get (calendar.day_of_month)); //Time Comparison recommendedSystem.out.println (Ca.after (NewDate ())); System.out.println (Ca.before (NewDate ())); //You can also get the time system for the specified time zoneSystem.out.println (Calendar.getinstance (locale.english)); /**Other Time operations **/ //current number of secondsSystem.out.println (System.currenttimemillis ()); System.out.println (NewDate (). GetTime ()); //Time FormattingSimpleDateFormat SF =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); System.out.println (Sf.format (Ca.gettime ())); System.out.println (Sf.parse ("2018-10-12 09:18:23"). After (NewDate ())); }}
Java Time Operations