Package com.lvxh.service;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Org.apache.commons.lang3.StringUtils;
Import Org.apache.log4j.Logger;
/**
* . Date Tool 2015-09-10
*
* @since V100R001C02
* @version V100R001C02
*/
Public abstract class Dateutil {
/**
* Initialize Log class
*/
private static final Logger LOG = Logger.getlogger (Dateutil.class);
/**
*. date format
*/
private static final String Date_format = "YYYY-MM-DD";
/**
*. date format
*/
public static final String Datetime_format = "Yyyy-mm-dd HH:mm:ss";
/**
*. date format
*/
private static final int millisencond_of_minute = 60 * 1000;
/**
* . Date Copy
*
* @param date
* Source Date Object
* @return The Date object after copying
*/
public static date Clone (date date) {
if (date! = null) {
Return (Date) Date.clone ();
}
return null;
}
/**
* Time type go to string
*
* @return String
*/
public static String Gettoday () {
Return Datetostr (New Date ());
}
/**
* Time type go to string
*
* @param date
* Date
*
* @return String
*/
public static String datetostr (date date) {
return Datetostr (date, date_format);
}
/**
* Time type go to string
*
* @param date
* Date
*
* @param format
* Format
*
* @return String
*/
public static string Datetostr (date date, string format) {
if (date = = null) {
Return "";
} else {
SimpleDateFormat SDF = new SimpleDateFormat (format);
return Sdf.format (date);
}
}
/**
* Time string converted to date
*
* @param date
* string to be converted by string
* @param format
* Conversion Format
* @return Date returned
*/
public static date Strtodate (string date, string format) {
Date time = null;
if (Stringutils.isempty (date)) {
Log.info ("date is null");
} else {
SimpleDateFormat SDF = new SimpleDateFormat (format);
try {
Time = Sdf.parse (date);
} catch (ParseException e) {
Log.error ("Parse Time exception", e);
}
}
return time;
}
/**
* Function Description: Time subtraction to get the number of minutes
*
* @param begindate
* Begindate
* @param endDate
* EndDate
* @return Long
*/
public static long subminutes (date begindate, date endDate) {
Return (Enddate.gettime ()-begindate.gettime ())/Millisencond_of_minute;
}
}
Date time Formatting (Java)