Java Date Tool class, Java Time Tool class, Java time format
>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
? Copyright Sweet Potato Yiu February 4, 2017 15:03:27 Saturday
http://www.cnblogs.com/fanshuyao/
Annex Download See: Http://fanshuyao.iteye.com/blog/2355386.
Java code
- Public static final String Date_time_pattern = "Yyyy-mm-dd HH:mm:ss";
- Public static final String Date_pattern = "Yyyy-mm-dd";
- /**
- * Date Added minus days
- * @param date if NULL, the current time
- * @param days plus minus
- * @param includetime whether to include a time or seconds, true to include
- * @return
- * @throws ParseException
- */
- Public static Date dateAdd (date date, int days, boolean includetime) throws parseexception{
- if (date = = null) {
- Date = new Date ();
- }
- if (!includetime) {
- SimpleDateFormat SDF = new SimpleDateFormat (Strutils.date_pattern);
- Date = Sdf.parse (Sdf.format (date));
- }
- Calendar cal = Calendar.getinstance ();
- Cal.settime (date);
- Cal.add (Calendar.date, days);
- return Cal.gettime ();
- }
- /**
- * Time formatted into a string
- * @param date Date
- * @param pattern if empty, then YYYY-MM-DD
- * @return
- * @throws ParseException
- */
- Public static string DateFormat (date date, string pattern) throws parseexception{
- if (Strutils.isblank (pattern)) {
- pattern = Strutils.date_pattern;
- }
- SimpleDateFormat SDF = new SimpleDateFormat (pattern);
- return Sdf.format (date);
- }
- /**
- * String parsed into a time object
- * @param datetimestring String
- * @param pattern if empty, then YYYY-MM-DD
- * @return
- * @throws ParseException
- */
- Public static Date dateparse (string datetimestring, string pattern) throws parseexception{
- if (Strutils.isblank (pattern)) {
- pattern = Strutils.date_pattern;
- }
- SimpleDateFormat SDF = new SimpleDateFormat (pattern);
- return Sdf.parse (datetimestring);
- }
- /**
- * Format Date time as a string with only date
- * @param dateTime Date
- * @return
- * @throws ParseException
- */
- Public static String datetimetodatestring (Date dateTime) throws parseexception{
- String datetimestring = Strutils.dateformat (DateTime, Strutils.date_time_pattern);
- return datetimestring.substring (0, 10);
- }
- /**
- * When, minutes, and seconds are 00:00:00, the datetime is formatted as a date-only string,
- * When, minutes and seconds are not 00:00:00, return directly
- * @param dateTime Date
- * @return
- * @throws ParseException
- */
- Public static String Datetimetodatestringiftimeendzero (Date dateTime) throws parseexception{
- String datetimestring = Strutils.dateformat (DateTime, Strutils.date_time_pattern);
- if (Datetimestring.endswith ("00:00:00")) {
- return datetimestring.substring (0, 10);
- }else{
- return datetimestring;
- }
- }
- /**
- * Format Date time as Date object, and Dateparse
- * @param dateTime Date
- * @return Date
- * @throws ParseException
- */
- Public static Date datetimetodate (date DateTime) throws parseexception{
- Calendar cal = Calendar.getinstance ();
- Cal.settime (DateTime);
- Cal.set (Calendar.hour_of_day, 0);
- Cal.set (Calendar.minute, 0);
- Cal.set (Calendar.second, 0);
- Cal.set (Calendar.millisecond, 0);
- return Cal.gettime ();
- }
>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
? Copyright Sweet Potato Yiu February 4, 2017 15:03:27 Saturday
http://www.cnblogs.com/fanshuyao/
Java Date Tool class, Java Time Tool class, Java time format