格式化日期为字符串,对Date类的封装。
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateUtil {
     private static SimpleDateFormat UnFormattedSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");;
     private static SimpleDateFormat StandardSDF = new SimpleDateFormat("yyyyMMddHHmmss");
     private static SimpleDateFormat LongDatedSDF = new SimpleDateFormat("yyyy-MM-dd");
     private static SimpleDateFormat ShortDateSDF = new SimpleDateFormat("yyyyMMdd");
     private static SimpleDateFormat ChineseLongDateTimedSDF = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
     private static SimpleDateFormat ChineseDatedSDF = new SimpleDateFormat("yyyy年MM月dd日");
     private static SimpleDateFormat StandardSDF_Milliseconds = new SimpleDateFormat("yyyyMMddHHmmssSSS");
     
     public static String getCurrentTime(SimpleDateFormat simpleDateFormat){
      return simpleDateFormat.format(new Date());
     }
     
     public static String getUnformattedsdfFormat() {
      return getCurrentTime(UnFormattedSDF);
     }

     public static String getStandardsdfFormat() {
      return getCurrentTime(StandardSDF);
     }

     public static String getLongdatedsdfFormat() {
      return getCurrentTime(LongDatedSDF);
     }

     public static String getShortdatesdfFormat() {

      return getCurrentTime(ShortDateSDF);
     }

     public static String getChineselongdatetimedsdfFormat() {
      return getCurrentTime(ChineseLongDateTimedSDF);
     }

     public static String getChinesedatedsdfFormat() {
      return getCurrentTime(ChineseDatedSDF);
     }

     public static String getStandardsdfMillisecondsFormat() {
      return getCurrentTime(StandardSDF_Milliseconds);
     }
    }

    本文为风林火山博客原创,转载请注明出处:www.flcoder.com