Java 时间Util类

 import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import com.paic.is.dispatch.TMPEntry; public class DateTimeUtil { public final static String LOCAL_SHORT_DATE_FORMAT = "yyyy-MM-dd"; public final static String LOCAL_LONG_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; public final static String STAND_LONG_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; public final static String STAND_SHORT_DATE_FORMAT = "yyyy/MM/dd"; public static Date getCurrentDate() { return new Date(System.currentTimeMillis()); } public static String getCurrentDateLocalFormatString() { return new SimpleDateFormat(LOCAL_LONG_DATE_FORMAT).format(getCurrentDate()); } public static String getCurrentDateFormatString(String dateFormat) { return new SimpleDateFormat(dateFormat).format(getCurrentDate()); } public static String getFormatString(Date date, String dateFormat) { return new SimpleDateFormat(dateFormat).format(date); } public static Date getDateByFormat(String dateString, String dateFormat) { if(StringUtil.IsEmpty(dateString) || StringUtil.IsEmpty(dateFormat)) { return null; } SimpleDateFormat format = new SimpleDateFormat(dateFormat); Date date = null; try { date = format.parse(dateString); } catch(Exception ex) { ExceptionDefaultHandler.handle(ex, TMPEntry.getCurrentTMPFileName() + ".log"); } return date; } public static Calendar getCalendarByDate(Date date) { Calendar calendar=Calendar.getInstance(); calendar.setTime(date); return calendar; } }

你可能感兴趣的:(Java)