Here you can find the source of getCurrentDateStr(String strFormat)
Parameter | Description |
---|---|
strFormat | a parameter |
public static String getCurrentDateStr(String strFormat)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static final String C_DATE_PATTON_DEFAULT = "yyyy-MM-dd"; public static String getCurrentDateStr() { Calendar cal = Calendar.getInstance(); Date currDate = cal.getTime(); return format(currDate); }/*from ww w . j a v a 2s . co m*/ /** * Return the current date in the specified format * * @param strFormat * @return */ public static String getCurrentDateStr(String strFormat) { Calendar cal = Calendar.getInstance(); Date currDate = cal.getTime(); return format(currDate, strFormat); } public static String format(Date aTs_Datetime) { return format(aTs_Datetime, C_DATE_PATTON_DEFAULT); } public static String format(Date aTs_Datetime, String as_Pattern) { if (aTs_Datetime == null || as_Pattern == null) return null; SimpleDateFormat dateFromat = new SimpleDateFormat(); dateFromat.applyPattern(as_Pattern); return dateFromat.format(aTs_Datetime); } /** * @param aTs_Datetime * @param as_Pattern * @return */ public static String format(Timestamp aTs_Datetime, String as_Pattern) { if (aTs_Datetime == null || as_Pattern == null) return null; SimpleDateFormat dateFromat = new SimpleDateFormat(); dateFromat.applyPattern(as_Pattern); return dateFromat.format(aTs_Datetime); } }