Package p1;import java.text.simpledateformat;import java.util.date;public class ts { public static void main (String[] args) {// calendar calendar = Calendar.getinstance (Locale.china);// long timestamp = calendar.gettime (). GetTime ()/1000; date date = new date (); long timestamp = Date.gettime (); system.out.println (TimeStamp); system.out.println (Transferlongtodate (timeStamp)); } private static string transferlongtodatE (long millsec) { simpledateformat sdf = new simpledateformat ("Yyyy-mm-dd hh:mm:sss"); date date= new date (millsec); return sdf.format (date); } }
I habitually put the date format of the full lowercase, and then found that the data is not right, Baidu a bit, found that M D D is a case of different meanings, refer to http://www.blogjava.net/algz/articles/324727.html, thank Bo Master ~
Mutual transformation of Java-long and dates