Java
Package Com.ikoo.demo; Import Java.text.simpledateformat;import Java.util.calendar;import java.util.Date; public class Dateutil {public static void main (string[] args) {/** * timestamp * 1.system.currenttim Emillis () * 2.new Date (). GetTime () * 3.calendar.getinstance (). Gettimeinmillis () * p.s. * Java acquisition Timestamp is accurate to the millisecond level, UNIX is accurate to the second level, so Java gets the timestamp needs to divide by 1000, can guarantee consistency * calendar.getinstance (). Gettimeinmillis () is the most time-consuming because C Anlendar to handle time zone problems */SYSTEM.OUT.PRINTLN ("System.currenttimemillis ():" + System.currenttimemillis ()); System.out.println ("New Date (). GetTime ():" + new Date (). GetTime ()); System.out.println ("Calendar.getinstance (). Gettimeinmillis ():" + calendar.getinstance (). Gettimeinmillis ()); System.out.println ("----------"); /** * Timestamp (date) Convert custom date format */Long TimeStamp = System.currenttimemillis (); System.out.println ("System.currenttimemillis ():" + TimeStamp); DatE date = new Date (); System.out.println ("New Date ():" + date); Long Datetimastamp = Date.gettime (); System.out.println ("Date.gettime ():" + date.gettime ()); String formatDate0 = Dateutil.timestamptoformatdate (System.currenttimemillis (), "Yyyy-mm-dd HH:mm:ss"); System.out.println ("FormatDate0:" + formatDate0); String formatDate1 = dateutil.timestamptoformatdate (New Date (), "Yyyy-mm-dd HH:mm:ss"); System.out.println ("formatDate1:" + formatDate1); String FormatDate2 = dateutil.timestamptoformatdate (new Date (). GetTime (), "Yyyy-mm-dd HH:mm:ss"); System.out.println ("FormatDate2:" + formatDate2); String formatDate3 = Dateutil.timestamptoformatdate (Calendar.getinstance (). GetTime (), "Yyyy-mm-dd HH:mm:ss"); System.out.println ("FormatDate3:" + formatDate3); }/** * Timestamp converted to formatted date * * @param dateobj Time Object * System.currenttimemillis () * New Date () * New Date (). GetTime () * calendar.getinstance (). Gettimeinmillis () * @param pattern Date format * YYYY-MM-DD HH:MM:SS * YYYY/MM/DD HH:mm:ss * yyyy year MM month DD Day HH:MM:SS * @r Eturn Sdf.format (Object dateobj) */public static string Timestamptoformatdate (object Dateobj, string pattern) { SimpleDateFormat SDF = new SimpleDateFormat (pattern); String formatdate = Sdf.format (dateobj); return formatdate; }}
Console Print Results:
System.Currenttimemillis():1503660334272NewDate ().GetTime():1503660334274Calendar.getinstance().Gettimeinmillis():1503660334299----------System.Currenttimemillis():1503660334328NewDate (): Fri - +: -: theCst .Date.GetTime():1503660334328FORMATDATE0:2017-08-25 +: -: theFormatDate1:2017-08-25 +: -: theFormatDate2:2017-08-25 +: -: theFormatDate3:2017-08-25 +: -: theProcess finished with exit code0
Java-Timestamp, date, Calendar, SimpleDateFormat