| | |
| | | private static SimpleDateFormat Format_16 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); |
| | | private static SimpleDateFormat Format_17 = new SimpleDateFormat("HH:mm"); |
| | | |
| | | /**时间格式转化iso8601 |
| | | * @param date 时间 |
| | | * @return 返回的时间格式字符串 |
| | | */ |
| | | public static String dateFormatISO8601(Date date) { |
| | | if(!SimpleTool.checkNotNull(date)){ |
| | | return ""; |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");//设置日期格式 |
| | | return df.format(date); |
| | | } |
| | | |
| | | /**时间格式转化 |
| | | * @param date 时间 |
| | | * @param format 时间格式 |
| | |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat(format);//设置日期格式 |
| | | return df.format(date); |
| | | } |
| | | |
| | | /**时间戳转时间 |
| | | * @param timestamp 时间戳 |
| | | * @param format 时间格式 |
| | | * @return 返回的时间格式字符串 |
| | | */ |
| | | public static Date timestampToDate(long timestamp, String format) { |
| | | SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sd = sdf.format(new Date(timestamp)); // 时间戳转换成时间 |
| | | return DateUtil.parseString(sd,"yyyy-MM-dd HH:mm:ss"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return Format_14.format(date); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 当前时间之前的时间与当前时间相差多少秒 |
| | | * @param startDate 当前时间之前的时间 |
| | | * @return |
| | | */ |
| | | public static int calLastedTime(Date startDate) { |
| | | long nowDate = new Date().getTime(); |
| | | long startDateTime = startDate.getTime(); |
| | | int diffSeconds = (int) ((nowDate - startDateTime) / 1000); |
| | | return diffSeconds; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 转换成yyyyMMddHHmmssSSS格式的日期字符串 |
| | | * |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static Date parseString(String str) throws Exception { |
| | | return Format_2.parse(str); |
| | | public static Date parseString(String str) { |
| | | try { |
| | | return Format_2.parse(str); |
| | | }catch (Exception e) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static Date parseString(String str, String format) throws Exception { |
| | | public static Date parseString(String str, String format) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat(format); |
| | | return sdf.parse(str); |
| | | try{ |
| | | return sdf.parse(str); |
| | | }catch (Exception e) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /**字符串转成时间yyyy-MM-dd HH:mm:ss*/ |
| | |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(dateTime); |
| | | c.add(Calendar.DATE, dayNum); |
| | | return c.getTime(); |
| | | } |
| | | |
| | | /**时间上月数叠加 |
| | | * @Author: ChenJiaHe |
| | | * @param dateTime 时间 |
| | | * @param dayNum 天数 |
| | | * @return |
| | | */ |
| | | public static Date addMonth(Date dateTime,int dayNum){ |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(dateTime); |
| | | c.add(Calendar.MONTH, dayNum); |
| | | return c.getTime(); |
| | | } |
| | | |
| | |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * 针对str格式的时间做转换 格式为"xx:xx" |
| | | * @param time 传入的时间 |
| | | * @return 返回分钟如果10:25,则返回625 |
| | | */ |
| | | public static int getMinuteNum(String time){ |
| | | |
| | | if(!StringUtils.isEmpty(time)) |
| | | { |
| | | String[] arr = time.split(":"); |
| | | if(arr != null && arr.length == 2) |
| | | { |
| | | return Integer.parseInt(arr[0]) * 60 + Integer.parseInt(arr[1]); |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | | |
| | | |
| | | } |
| | | |
| | | } |