|
|
@@ -4,6 +4,7 @@ import org.apache.log4j.Logger;
|
|
|
import org.apache.log4j.PropertyConfigurator;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -109,19 +110,35 @@ public class BaseUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 时间戳转换成日期格式字符串
|
|
|
- * @param seconds
|
|
|
+ * 转换成日期格式字符串
|
|
|
+ * @param date
|
|
|
* @param format
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String timeStamp2Date(Long seconds,String format) {
|
|
|
- if(seconds == null || seconds==0){
|
|
|
- return "";
|
|
|
- }
|
|
|
+ public static String date2String(Date date,String format) {
|
|
|
if(format == null || format.isEmpty()){
|
|
|
format = "yyyy-MM-dd HH:mm:ss";
|
|
|
}
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
- return sdf.format(new Date(seconds));
|
|
|
+ if(date == null){
|
|
|
+ return sdf.format(new Date());
|
|
|
+ }
|
|
|
+ return sdf.format(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换成日期格式字符串
|
|
|
+ * @param seconds
|
|
|
+ * @param format
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Date string2Date(String seconds,String format) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
+ try {
|
|
|
+ return sdf.parse(seconds);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return new Date();
|
|
|
}
|
|
|
}
|