ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;/*** Created by Zay on 2016/12/9.*/ Public classTimetest { Public Static voidMain (string[] args) {//(1) Get the current timeSystem.out.println (NewDate ()); System.out.println (Calendar.getinstance ()); System.out.println (System.currenttimemillis ()); /*First output Fri Dec 00:28:05 CST*/ /*second output java.util.gregoriancalendar[time=1481214485061,arefieldsset=true,areallfieldsset=true,lenient=true, Zo Ne=sun.util.calendar.zoneinfo[id= "Asia/shanghai", Offset=28800000,dstsavings=0, usedaylight=false,transitions=19 , Lastrule=null],firstdayofweek=1, Minimaldaysinfirstweek=1,era=1,year=2016,month=11,week_of_year=50,week_of_ Month=2,day_of_month=9, Day_of_year=344,day_of_week=6,day_of_week_in_month=2,am_pm=0,hour=0,hour_of_day=0, Minute=28,second=5, millisecond=61,zone_offset=28800000,dst_offset=0]*/ /*The third one outputs the timestamp exactly to the millisecond level 1481214485061*/ //(2) Time formatSimpleDateFormat simple =NewSimpleDateFormat ("Yyyy-mm-dd"); System.out.println (Simple.format (NewDate ())); //(3) Common date arithmetic (plus minus according to calendar rules)Calendar calendar=calendar.getinstance ();//get a calendar using the default time zone and locale. Calendar.add (calendar.date,-2);//Gets the date of the first 10 days of the current dateSystem.out.println (Calendar.gettime ()); Calendar.set (2016,12,9);//sets the value of the Calendar field year, MONTH, and Day_of_month. //(4) Date, calendar, timestamp string three conversions//Get Date typeDate Date=calendar.gettime ();//Calendar, Date//get the type of calendarCalendar.settime (NewDate ());//date, Calendar//get time stamp stringCalendar.gettimeinmillis ();//Date -and timestamp string }}
"Java" About time