123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package com.yihu.utils;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import com.coreframework.remoting.reflect.RpcException;
- /**
- * 公共工具类
- * @author chenzhibin <br> 2017-5-9 下午18:20:30
- */
- public class Utils {
-
- public static String getException(Exception e) {
- e.printStackTrace();
- String str = RpcException.getExceptionInfo(e);
- if (str.indexOf("Caused by") != -1) {
- str = str.substring(str.indexOf("Caused by:") + 10);
- if (str.indexOf("\r\n\t") > 0) {
- str = str.substring(0, str.indexOf("\r\n\t"));
- }
- } else {
- str = e.toString();
- }
- return str;
- }
- //时间做对比,返回相差几天
- public static int daysBetween(String smdate,String bdate){
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Calendar cal = Calendar.getInstance();
- long time1 = 0;
- long time2 = 0;
- try{
- cal.setTime(sdf.parse(smdate));
- time1 = cal.getTimeInMillis();
- cal.setTime(sdf.parse(bdate));
- time2 = cal.getTimeInMillis();
- }catch(Exception e){
- e.printStackTrace();
- }
- long between_days=(time2-time1)/(1000*3600*24);
-
- return Integer.parseInt(String.valueOf(between_days));
- }
- }
|