479dd5ed660ca0c74035d0f86672f46b81de9fcf.svn-base 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.yihu.utils;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import com.coreframework.remoting.reflect.RpcException;
  5. /**
  6. * 公共工具类
  7. * @author chenzhibin <br> 2017-5-9 下午18:20:30
  8. */
  9. public class Utils {
  10. public static String getException(Exception e) {
  11. e.printStackTrace();
  12. String str = RpcException.getExceptionInfo(e);
  13. if (str.indexOf("Caused by") != -1) {
  14. str = str.substring(str.indexOf("Caused by:") + 10);
  15. if (str.indexOf("\r\n\t") > 0) {
  16. str = str.substring(0, str.indexOf("\r\n\t"));
  17. }
  18. } else {
  19. str = e.toString();
  20. }
  21. return str;
  22. }
  23. //时间做对比,返回相差几天
  24. public static int daysBetween(String smdate,String bdate){
  25. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  26. Calendar cal = Calendar.getInstance();
  27. long time1 = 0;
  28. long time2 = 0;
  29. try{
  30. cal.setTime(sdf.parse(smdate));
  31. time1 = cal.getTimeInMillis();
  32. cal.setTime(sdf.parse(bdate));
  33. time2 = cal.getTimeInMillis();
  34. }catch(Exception e){
  35. e.printStackTrace();
  36. }
  37. long between_days=(time2-time1)/(1000*3600*24);
  38. return Integer.parseInt(String.valueOf(between_days));
  39. }
  40. }