Tag:ring mat Extract cal ddd led pattern stat import
Import Java.text.parseexception;import java.text.simpledateformat;import Java.util.calendar;import java.util.Date The/** * Date Tool class uses the default "YYYY-MM-DD HH:MM:SS" format Date * */public Final class Dateutils {/** * English shorthand (default) such as: 2010-12-01 */ public static String Format_short = "YYYY-MM-DD"; /** * English full name: 2010-12-01 23:15:06 */public static String Format_long = "Yyyy-mm-dd HH:mm:ss"; /** * Accurate to milliseconds full time such as: Yyyy-mm-dd HH:mm:ss. S */public static String Format_full = "Yyyy-mm-dd HH:mm:ss. S "; /** * Chinese Shorthand: December 01, 2010 */public static String FORMAT_SHORT_CN = "yyyy mm month DD"; /** * Chinese full name: December 01, 2010 23:15 06 seconds */public static String FORMAT_LONG_CN = "yyyy mm month DD day hh" mm min SS second "; /** * Accurate to milliseconds full Chinese time */public static String FORMAT_FULL_CN = "yyyy mm month DD day hh" mm min ss sec sss msec "; /** * Gets the default date pattern */public static String Getdatepattern () {return format_long; }/** * Returns the current date according to the preset format * * @return * * public static String Getnow () {return format (new Date ()); /** * Returns the current date according to the user format * * @param format * @return */public static string Getnow (string format) {return format (new Date (), format); /** * format date with preset format * * @param date * @return */public static String format (date date) { return format (date, Getdatepattern ()); /** * format date with user format * * @param date * Date * @param pattern * Date format * @ return */public static string format (date date, string pattern) {String returnvalue = ""; if (date! = null) {SimpleDateFormat df = new SimpleDateFormat (pattern); returnvalue = Df.format (date); } return (returnvalue); /** * Extract string date using preset format * * @param strdate * Date String * @return */public static date Parse (String strdate) {return parse (strdate, Getdatepattern ()); /** * Extract string date using user format * * @param strdate * Date String * @param pattern * Date format * @return */public static Date parse (string strdate, String pattern) {SimpleDateFormat df = new Simpl Edateformat (pattern); try {return df.parse (strdate); } catch (ParseException e) {e.printstacktrace (); return null; }}/** * Add a few months to the date * * @param date * Date * @param n * Number of month to increase * @ return */public static date Addmonth (date date, int n) {Calendar cal = Calendar.getinstance (); Cal.settime (date); Cal.add (Calendar.month, N); return Cal.gettime (); /** * Add days to date * * @param date * Date * @param n * Number of days to increase * @return */public static date Addday (date date, int n) {Calendar cal = Calendar.getinstance (); Cal.settime (date); Cal.add (calendar.date, N); return Cal.gettime (); }/** * gets timestamp */public static String gettimestring () {SimpleDateFormat df = new SimpleDateFormat (FO Rmat_full); Calendar calendar = Calendar.getinstance (); Return Df.format (Calendar.gettime ()); /** * Gets the date year * * @param date * Date * @return */public static String GetYear (Da Te date) {return format (date). substring (0, 4); }/** * By default format string distance today * * @param date * Date String * @return */public static int Countdays (String date) {Long T = calendar.getinstance (). GetTime (). GetTime (); Calendar C = calendar.getinstance (); C.settime (Parse (date)); Long T1 = C.gettime (). GetTime (); return (int) (t/1000-t1/1000)/3600/24; }/** * by user format string distance today * * @param date * Date String * @param format * Date formats * @return * * public static int Countdays (string date, string format) {Long T = calendar.getinstance (). GetTime (). GetTime (); Calendar C = calendar.getinstance (); C.settime (Parse (date, format)); Long T1 = C.gettime (). GetTime (); return (int) (t/1000-t1/1000)/3600/24; }}
"Java" Dateutil (1)