One, the date and the conversion of long type data
Public class hello{ publicstaticvoidthrows Exception { // date converted to long New Date (); long Currentdateinlong = currentdateindate.gettime (); System.out.println (currentdateindate); System.out.println (Currentdateinlong); } }
Two, a long type is converted to a date
Public class hello{ publicstaticvoidthrows Exception { // date converted to long long Currentdateinlong = system.currenttimemillis (); New Date (currentdateinlong); System.out.println (currentdateindate); System.out.println (Currentdateinlong); } }
Third, date formatting (format the date as a string)
Public classhello{ Public Static voidMain (string[] args)throwsException {//date converted to long LongCurrentdateinlong =System.currenttimemillis (); Date currentdateindate=NewDate (Currentdateinlong); SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. SSSS "); String currentdateinstring=Sdf.format (currentdateindate); System.out.print (currentdateinstring); } }
Iv. parsing of dates (converting strings to dates)
Public class hello{ publicstaticvoidthrows Exception { = " 2016-08-07 19:24:03.0528 "; New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. SSSS "); = Sdf.parse (currentdateinstring); System.out.print (currentdateindate); } }
V. Using the Calendar class to get the parts of a date
Public class hello{ publicstaticvoidthrows Exception { = calendar.getinstance (); SYSTEM.OUT.PRINTLN ("Year:" + Calendar.get (calendar.year)); System.out.println ("Month:" + (Calendar.get (calendar.month) + 1)); System.out.println ("Day:" + Calendar.get (calendar.day_of_month));} }
Date processing in Java