标签:only pattern mon trace 工具 att 定时 todo span
package com.gwt.utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; /** * * @ClassName: DateFormatUtil * @Description: TODO(时间格式化工具类) * @author wcs * @date 2018年4月11日 下午2:01:47 * */ public class DateFormatUtil { public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm"; public static final String HOUR_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_PATTERN = "yyyy-MM-dd"; public static final String MONTH_PATTERN = "yyyy-MM"; public static final String YEAR_PATTERN = "yyyy"; public static final String MINUTE_ONLY_PATTERN = "mm"; public static final String HOUR_ONLY_PATTERN = "HH"; public static final String DATETIME_PATTERN = "yyyyMMddHHmmss"; public static final String DATEPATTERN = "yyyyMMdd"; /** * * @Title: dateFormat * @Description: TODO(时间格式化) * @param @param date * @param @param pattern * @param @return * @param @throws ParseException 设定文件 * @return String 返回类型 * @throws */ public static String dateFormat(Date date, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.SIMPLIFIED_CHINESE); return sdf.format(date); } /** * * @Title: stringToDate * @Description: TODO(字符串格式化日期) * @param @param dateString * @param @param pattern * @param @return 设定文件 * @return Date 返回类型 * @throws */ public static Date stringToDate(String dateString, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); try { return sdf.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return null; } /** * * @Title: plusDay * @Description: TODO(给指定时间加上天数) * @param @param num * @param @param newDate * @param @param format * @param @return 设定文件 * @return String 返回类型 * @throws */ public static String plusDay(int num, String date, String formats) { SimpleDateFormat format = new SimpleDateFormat(formats); try { Date oldDate = format.parse(date); Calendar ca = Calendar.getInstance(); ca.setTime(oldDate); ca.add(Calendar.DATE, num);// num为增加的天数,可以改变的 oldDate = ca.getTime(); String enddate = format.format(oldDate); return enddate; } catch (ParseException e) { e.printStackTrace(); return null; } } /** * * @Title: plusYear * @Description: TODO(给指定时间加上年数) * @param @param num * @param @param date * @param @param formats * @param @return 设定文件 * @return String 返回类型 * @throws */ public static String plusYear(int num, String date, String formats) { SimpleDateFormat format = new SimpleDateFormat(formats); try { Date oldDate = format.parse(date); Calendar ca = Calendar.getInstance(); ca.setTime(oldDate); ca.add(Calendar.YEAR, num);// num为增加的年数,可以改变的 oldDate = ca.getTime(); String enddate = format.format(oldDate); return enddate; } catch (ParseException e) { e.printStackTrace(); return null; } } }
标签:only pattern mon trace 工具 att 定时 todo span
原文地址:https://www.cnblogs.com/wcss/p/12125637.html