时间转换的单例模式

/*

*时间转换

*/

package com.lokomotive.common.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author xuejie.xiao
 *
 */
public class DateFormatUtils {
   
    private final static DateFormat[] ACCEPT_DATE_FORMATS = {
        new SimpleDateFormat("YYYY-MM-dd"),
        new SimpleDateFormat("yyyy/MM/dd"),
        new SimpleDateFormat("dd/MM/yyyy"),
        new SimpleDateFormat("YYYY-MM-dd HH:mm:ss")
        };
   
    private DateFormatUtils(){}
   
    public static String formatDate(Date date){
        return DateFormat.getDateInstance().format(date);
    }
   
   
    public static Date parseDate(String arg0){
          Date date = null;
          for(DateFormat format : ACCEPT_DATE_FORMATS){
              try {
                  return format.parse(arg0);
              } catch (Exception e) {   
                  continue;
              }
             
          }
          return date;
    }
}

猜你喜欢

转载自jin-deng.iteye.com/blog/1597180