| | |
| | | throw e; |
| | | } |
| | | } |
| | | public static String getShortDateStr(Date date) { |
| | | String nowDate = ""; |
| | | try { |
| | | nowDate = sdfShort.format(date); |
| | | return nowDate; |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Descrption:取得当前日期,格式为:YYYY-MM-DD |
| | |
| | | return new Timestamp(System.currentTimeMillis()); |
| | | } |
| | | } |
| | | public static Date getDateFromString2(String strDate) { |
| | | if (StringUtils.isEmpty(strDate)) { |
| | | return new Date(System.currentTimeMillis()); |
| | | } |
| | | try { |
| | | return sdfLongTimePlus.parse(strDate); |
| | | } catch (Exception ex) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | // ----------------------------------------------------------------------- |
| | | public static Date parseFromFormats(String aValue) { |
| | |
| | | |
| | | public static void main(String[] args) { |
| | | try { |
| | | System.out.println(RandomStringUtils.randomNumeric(3)); |
| | | System.out.println((int)(3.222)); |
| | | |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 2个日期之间相差分钟数 |
| | | * @param begin |
| | | * @param end |
| | | * @return |
| | | */ |
| | | public static Integer betweenMin(Date begin, Date end) { |
| | | if(begin ==null ){ |
| | | return 0; |
| | | } |
| | | long createTime =begin.getTime();//获取创建时间的时间戳 |
| | | long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//获取当前时间的时间戳 |
| | | long diff=(currentTime-createTime)/1000/60;//获取两个时间相差的分钟 |
| | | return (int)diff + 1 ; |
| | | } |
| | | |
| | | public static Integer between(Date begin, Date end) { |
| | | if(begin ==null ){ |
| | | return 0; |
| | | } |
| | | long createTime =begin.getTime();//获取创建时间的时间戳 |
| | | long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//获取当前时间的时间戳 |
| | | long diff=(currentTime-createTime)/1000/60;//获取两个时间相差的分钟 |
| | | return (int)diff; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算耗时 |
| | | * @param start |
| | |
| | | return consuming.toString(); |
| | | } |
| | | |
| | | } |
| | | } |