Package com.util; Import Java.sql.Timestamp; Import Java.text.DateFormat; Import java.text.ParseException; Import Java.text.SimpleDateFormat; Import Java.util.Calendar; Import Java.util.Date; Public class Commondateparseutil { public static final String Eng_date_fromat = "EEE, d MMM yyyy z"; public static final String yyyy_mm_dd_hh_mm_ss = "Yyyy-mm-dd HH:mm:ss"; public static final String yyyy_mm_dd_hh_mm = "Yyyy-mm-dd hh:mm"; public static final String yyyy_mm_dd = "YYYY-MM-DD"; public static final String YYYY = "YYYY"; public static final String mm = "mm"; public static final String dd = "DD"; /** * @param date * @return * @ author Wang jianming * @ creation Date 2012-7-13 * @ Create Time 12:22:40 * Description--Format Date Object */ public static date date2date (date date, String format STR) { simpledateformat SDF = new SimpleDateFormat (FORMATSTR); string str = Sdf.format ( Date); try { date = sdf.parse (str); } catch (Exception e) { &nb Sp; return null; } return date; } /** * @param date * @return * @ Author Wang Jianming * @ Creation Date 2012-7-13 * @ creation Time 12:24:19 * Description--time object converted to string */ public static string date2string (date date, String formatstr) { String strdate = ""; SimpleDateFormat SDF = new SimpleDateFormat (FORMATSTR); Strdate = Sdf.format (date); return strdate; } /** * @param date * @return * @ Author Wang Jianming * @ Creation Date 2012-7-13 * @ creation Time 12:24:19 * @ Description--sql Time object converted to string */ public static string timestamp2string (Timestamp Timestamp, string formatstr) { String strdate = ""; SimpleDateFormat SDF = new SimpleDateFormat (FORMATSTR); Strdate = Sdf.format (timestamp); return strdate; } /** * @param datestring * @param formatstr * @return * @ author Wang jianming &n Bsp * @ Creation Date 2012-7-13 * @ creation time 1:09:24 * @ Description--string converted to time object */ public static Date s Tring2date (String datestring, String formatstr) { date formatedate = null; dateformat format = new SimpleDateFormat (FORMATSTR); try { formatedate = Format.parse (datestring); } catch ( ParseException e) { return null; } return formatedate; .} /** * @param date * @return * @ Author Wang Jianming * @ Creation Date 2012-10-10 * @ creation Time 09:18:36 * @ description--date type conversion to timestamp type */ public static Timestamp Date2timestamp (date date) { if (date = null) return null; return new Timestamp (Date.gettime ()); } /** * @return * @ Author Wang Jianming * @ Creation Date 2012-9-13 * @ creation Time 05:02:57 * Description--Get current year */ public static String Getnowyear () { SimpleDateFormat SDF = new SimpleDateFormat (YYYY); Return Sdf.format (New Date ()); } /** * @return * @ author Wang jianming * @ creation Date 2012-9-13 * @ creation time PM 05:03:15 &nbs P * @ Description--get current month */ public static String Getnowmonth () { simpledateformat sdf = new Si Mpledateformat (MM); return Sdf.format (New Date ()); } /** * @return * @ author Wang jianming * @ creation Date 2013-01-24 * @ creation time 08:41 : * @ description--Get day in current date */ public static String Getnowday () { simpledateform At SDF = new SimpleDateFormat (DD); return Sdf.format (New Date ()); } /** * @param time * @return * @ author Wang jianming * @ creation Date 2012-6-17 * @ creation Time 10:19:31 * @ description--Chinese information for specified time distance at current time */ public static String Getlnow (long time) { calendar cal = Calendar.getinstance (); long Timel = Cal.gettimeinmillis ()-time; if (timel/1000 <) { return "within 1 minutes"; } else if (timel/1000 {<) { return timel/1000/60 + minutes ago; } else if (timel/1000/60/60 <) { return timel/1000/60/60 + hours ago; } else { re Turn timel/1000/60/60/24 + "days ago"; } } } |