例子
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
//类说明:时间帮助处理公共类
public class TimeUtil {
public static final String PATTERN_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static final String PATTERN_YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
public static final String PATTERN_YYYYMMDD = "yyyyMMdd";
public static final String DATE_PATTERN_YYYY_MM_DD = "yyyy-MM-dd";
public static String formatDateToString(Date date) {
if (date == null)
return "";
return new SimpleDateFormat(TimeUtil.PATTERN_YYYYMMDDHHMMSS).format(date);
}
public static String formatCurrentDateToString(String pattern) {
return formatDateToString(new Date(), pattern);
}
public static String formatDateToString(Date date, String pattern) {
return new SimpleDateFormat(pattern).format(date);
}
public static void main(String []args){
//System.out.println(TimeUtil.formatDateToString(new Date()));
System.out.println(formatCurrentDateToString(PATTERN_YYYYMMDDHHMMSSSSS));
System.out.println("+++++++++++++++==");
//UUID uuid = UUID.randomUUID();
//System.out.println(uuid.toString());
}
}
输出结果
20131118135653968
+++++++++++++++==