Self-summary, what is not satisfied with the place, you can help correct the supplement, thank you!
Purpose: SimpleDateFormat class can be a very casual combination of date and time format, more than simply yyyy-mm-dd this format
Nonsense not much to say on the code
Test class Datetest
Packagecom.core.test;Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;Importjava.util.Date; Public classDatetest { Public Static voidMain (string[] args)throwsparseexception {SimpleDateFormat sdf0=NewSimpleDateFormat ("YyyyMMdd"); SimpleDateFormat SDF1=NewSimpleDateFormat ("Yyyy-mm-dd"); SimpleDateFormat SDF2=NewSimpleDateFormat ("yyyy mm month DD Day"); SimpleDateFormat sdf3=NewSimpleDateFormat ("ddmmyyyy"); String TIME0= "20140916"; String time1= "2014-09-16"; String time2= "September 16, 2014"; String Time3= "16092014"; Convertstamp (sdf0, TIME0); Convertstamp (SDF1, time1); Convertstamp (SDF2, time2); Convertstamp (SDF3, Time3); LongStamp = 1410796800000L; Convertdate (sdf0, stamp); Convertdate (SDF1, stamp); Convertdate (SDF2, stamp); Convertdate (SDF3, stamp); } //Date converted to timestamp Public Static voidConvertstamp (simpledateformat format, String time)throwsparseexception {Date Date=Format.parse (time); System.out.println (Date.gettime ()); } //time stamp converted to date Public Static voidConvertdate (SimpleDateFormat SDF,Longstamp) {String Date= Sdf.format (NewDate (stamp)); SYSTEM.OUT.PRINTLN (date); }}
Operation Result:
1410796800000141079680000014107968000001410796800000201409162014-09-16September 16, 2014 16092014
SimpleDateFormat is very flexible, haha.
Java SimpleDateFormat conversion between date and time stamp