DateUtil

package com.businessmatrix.common.util;

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

import org.apache.commons.lang3.time.DateUtils;

import com.businessmatrix.common.exception.RTException;

public class DateUtil extends DateUtils
{
	static public String format(Date date,String pattern) { return new SimpleDateFormat(pattern).format(date); }
	static public String format(long date,String pattern) { return format(new Date(date), pattern); }
	static public Date parseDate(String str,String ...parsePatterns) throws RTException {
		try {
			return DateUtils.parseDate(str, parsePatterns);
		}
		catch (ParseException e) {
			throw new RTException(e);
		}
	}
	static public Date parseDate(String str,String parsePattern) throws RTException {
		try {
			return DateUtils.parseDate(str, new String[]{parsePattern});
		}
		catch(ParseException e) {
			throw new RTException(e);
		}
	}
	
	public static void main(String argc[]) {
		System.out.println(DateUtil.format(new Date(), "yyyyMMdd-HHmmss-SSS_"));
	}
}

你可能感兴趣的:(DateUtil)