Dates are frequently used in projects, including the formatting of dates. Here are a few of the more commonly used tool classes.
ImportJava.text.SimpleDateFormat;Importjava.util.Date;Importorg.apache.commons.lang.time.DateFormatUtils;ImportOrg.apache.commons.lang.time.FastDateFormat; Public classTestController { Public Static voidmain (String [] args) {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyymmddhhmmsssss"); String ff1= Sdf.format (NewDate ()); System.out.println (FF1); Dateformatutils DF=Newdateformatutils (); Fastdateformat FF2= Fastdateformat.getinstance ("Yyyymmddhhmmsssss"); String format= Ff2.format (NewDate ()); SYSTEM.OUT.PRINTLN (format); String FF3= Dateformatutils.format (NewDate (), "Yyyymmddhhmmsssss"); System.out.println (FF3); }}
Among them, SimpleDateFormat is more commonly used, this is provided by the JDK, but this class is not thread-safe, The more thread-safe use is the Dateformatutils and Fastdateformat two tool classes provided in Apache's common package.
The operating result is:
20150901161033217
20150901161033273
20150901161033275
YYYY year
MM Month
DD Day
HH24 Hour System
MM points
SS sec
SSS milliseconds 3 bit, not enough to be padded 0
Easy-to-use classes in Java