|
@@ -1,5 +1,6 @@
|
|
|
/**
|
|
/**
|
|
|
* All rights Reserved, Designed By 上海风声企业信用征信有限公司
|
|
* All rights Reserved, Designed By 上海风声企业信用征信有限公司
|
|
|
|
|
+ *
|
|
|
* @Title: DateUtils.java
|
|
* @Title: DateUtils.java
|
|
|
* @Package com.riskraider.fxld.utils
|
|
* @Package com.riskraider.fxld.utils
|
|
|
* @Description: TODO(用一句话描述该文件做什么)
|
|
* @Description: TODO(用一句话描述该文件做什么)
|
|
@@ -29,304 +30,306 @@ import java.util.Date;
|
|
|
*/
|
|
*/
|
|
|
public class DateUtils {
|
|
public class DateUtils {
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * (精确到天的)日期样式
|
|
|
|
|
- */
|
|
|
|
|
- public static final String PATTERN_TO_DAYS = "yyyy-MM-dd";
|
|
|
|
|
- public static final String PATTERN_TO_DAYS2 = "yyyy.MM.dd";
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * (精确到秒的)日期样式
|
|
|
|
|
- */
|
|
|
|
|
- public static final String PATTERN_TO_SECONDS = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
-
|
|
|
|
|
- public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(PATTERN_TO_DAYS);
|
|
|
|
|
- public static final DateTimeFormatter dateFormatter2 = DateTimeFormatter.ofPattern(PATTERN_TO_DAYS2);
|
|
|
|
|
-
|
|
|
|
|
- public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(PATTERN_TO_SECONDS);
|
|
|
|
|
-
|
|
|
|
|
- public static final DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getToday
|
|
|
|
|
- * @Description: 获取今天的日期
|
|
|
|
|
- * @param @return 设定文件
|
|
|
|
|
- * @return Date 返回类型
|
|
|
|
|
- * @throws
|
|
|
|
|
- * @author shiyong
|
|
|
|
|
- * @date 2017年8月24日 下午2:11:03
|
|
|
|
|
- */
|
|
|
|
|
- public static Date getToday() {
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
-
|
|
|
|
|
- return cal.getTime();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getYesterday
|
|
|
|
|
- * @Description: 获取昨天的日期
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:18:38
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: Date
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static Date getYesterday() {
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
- cal.add(Calendar.DATE, -1);
|
|
|
|
|
-
|
|
|
|
|
- return cal.getTime();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getTomorrow
|
|
|
|
|
- * @Description: 获取明天的日期
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:19:28
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: Date
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static Date getTomorrow() {
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
- cal.add(Calendar.DATE, 1);
|
|
|
|
|
-
|
|
|
|
|
- return cal.getTime();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getTodayStr
|
|
|
|
|
- * @Description: 获取今天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:21:51
|
|
|
|
|
- * @param: @param pattern
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getTodayStr(String pattern){
|
|
|
|
|
- SimpleDateFormat format = new SimpleDateFormat(pattern);
|
|
|
|
|
-
|
|
|
|
|
- return format.format(getToday());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getTodayStr
|
|
|
|
|
- * @Description: 获取今天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:33:22
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getTodayStr(){
|
|
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
- return format.format(getToday());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getYesterdayStr
|
|
|
|
|
- * @Description: 获取昨天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:21:11
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getYesterdayStr(){
|
|
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
- return format.format(getYesterday());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getTomorrowStr
|
|
|
|
|
- * @Description: 获取明天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:25:00
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getTomorrowStr(){
|
|
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
- return format.format(getTomorrow());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: formatDate
|
|
|
|
|
- * @Description: 格式化日期
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2018年1月4日 上午9:30:29
|
|
|
|
|
- * @param: @param format
|
|
|
|
|
- * @param: @param date
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String formatDate(Date date) {
|
|
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
- return dateFormat.format(date);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public static String formatDate(LocalDate date) {
|
|
|
|
|
- return dateFormatter.format(date);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: formatDateTime
|
|
|
|
|
- * @Description: 格式化整个日期时间
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2018年6月25日 下午1:30:24
|
|
|
|
|
- * @param: @param date
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String formatDateTime(Date date) {
|
|
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
-
|
|
|
|
|
- return dateFormat.format(date);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public static String formatDateTime(LocalDateTime dateTime) {
|
|
|
|
|
- return dateTimeFormatter.format(dateTime);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: parseDate
|
|
|
|
|
- * @Description: 格式化日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:40:06
|
|
|
|
|
- * @param: @param dateString
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @param: @throws ParseException
|
|
|
|
|
- * @return: Date
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static Date parseDate(String dateString) throws ParseException{
|
|
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
- return dateFormat.parse(dateString);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: parseDateTime
|
|
|
|
|
- * @Description: 格式化时间字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午7:40:24
|
|
|
|
|
- * @param: @param dateString
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @param: @throws ParseException
|
|
|
|
|
- * @return: Date
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static Date parseDateTime(String dateString) throws ParseException{
|
|
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
-
|
|
|
|
|
- return dateFormat.parse(dateString);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getFewDateStrsByDate
|
|
|
|
|
- * @Description: 获取近几天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午8:26:40
|
|
|
|
|
- * @param: @param date
|
|
|
|
|
- * @param: @param num
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getFewDateStrsByDate(Date date, int num){
|
|
|
|
|
- StringBuffer str = new StringBuffer();
|
|
|
|
|
-
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
-
|
|
|
|
|
- cal.setTime(date);
|
|
|
|
|
-
|
|
|
|
|
- cal.add(Calendar.DATE, -(num-1));
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
-
|
|
|
|
|
- for(int i=0;i<num-1;i++){
|
|
|
|
|
- cal.add(Calendar.DATE, 1);
|
|
|
|
|
-
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //去掉最后的逗号
|
|
|
|
|
-
|
|
|
|
|
- return str.substring(0, str.length()-1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getFewDateStrsByWeek
|
|
|
|
|
- * @Description: 获取近几周同一天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午8:33:23
|
|
|
|
|
- * @param: @param date
|
|
|
|
|
- * @param: @param num
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getFewDateStrsByWeek(Date date, int num){
|
|
|
|
|
- StringBuffer str = new StringBuffer();
|
|
|
|
|
-
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
-
|
|
|
|
|
- cal.setTime(date);
|
|
|
|
|
-
|
|
|
|
|
- cal.add(Calendar.WEEK_OF_YEAR, -(num-1));
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
-
|
|
|
|
|
- for(int i=0;i<num-1;i++){
|
|
|
|
|
- cal.add(Calendar.WEEK_OF_YEAR, 1);
|
|
|
|
|
-
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //去掉最后的逗号
|
|
|
|
|
-
|
|
|
|
|
- return str.substring(0, str.length()-1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @Title: getFewDateStrsByMonth
|
|
|
|
|
- * @Description: 获取近几月同一天的日期字符串
|
|
|
|
|
- * @author: 施勇
|
|
|
|
|
- * @date: 2019年1月17日 上午8:31:31
|
|
|
|
|
- * @param: @param date
|
|
|
|
|
- * @param: @param num
|
|
|
|
|
- * @param: @return
|
|
|
|
|
- * @return: String
|
|
|
|
|
- * @throws
|
|
|
|
|
- */
|
|
|
|
|
- public static String getFewDateStrsByMonth(Date date, int num){
|
|
|
|
|
- StringBuffer str = new StringBuffer();
|
|
|
|
|
-
|
|
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
|
-
|
|
|
|
|
- cal.setTime(date);
|
|
|
|
|
-
|
|
|
|
|
- cal.add(Calendar.MONTH, -(num-1));
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
-
|
|
|
|
|
- for(int i=0;i<num-1;i++){
|
|
|
|
|
- cal.add(Calendar.MONTH, 1);
|
|
|
|
|
-
|
|
|
|
|
- str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //去掉最后的逗号
|
|
|
|
|
-
|
|
|
|
|
- return str.substring(0, str.length()-1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * (精确到天的)日期样式
|
|
|
|
|
+ */
|
|
|
|
|
+ public static final String PATTERN_TO_DAYS = "yyyy-MM-dd";
|
|
|
|
|
+ public static final String PATTERN_TO_DAYS2 = "yyyy.MM.dd";
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * (精确到秒的)日期样式
|
|
|
|
|
+ */
|
|
|
|
|
+ public static final String PATTERN_TO_SECONDS = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
+ public static final String PATTERN_TO_MINUTES = "yyyy-M-d HH:mm";
|
|
|
|
|
+
|
|
|
|
|
+ public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(PATTERN_TO_DAYS);
|
|
|
|
|
+ public static final DateTimeFormatter dateFormatter2 = DateTimeFormatter.ofPattern(PATTERN_TO_DAYS2);
|
|
|
|
|
+
|
|
|
|
|
+ public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(PATTERN_TO_SECONDS);
|
|
|
|
|
+ public static final DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern(PATTERN_TO_MINUTES);
|
|
|
|
|
+
|
|
|
|
|
+ public static final DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getToday
|
|
|
|
|
+ * @Description: 获取今天的日期
|
|
|
|
|
+ * @param @return 设定文件
|
|
|
|
|
+ * @return Date 返回类型
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ * @author shiyong
|
|
|
|
|
+ * @date 2017年8月24日 下午2:11:03
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Date getToday() {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+
|
|
|
|
|
+ return cal.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getYesterday
|
|
|
|
|
+ * @Description: 获取昨天的日期
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:18:38
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: Date
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Date getYesterday() {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.add(Calendar.DATE, -1);
|
|
|
|
|
+
|
|
|
|
|
+ return cal.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getTomorrow
|
|
|
|
|
+ * @Description: 获取明天的日期
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:19:28
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: Date
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Date getTomorrow() {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.add(Calendar.DATE, 1);
|
|
|
|
|
+
|
|
|
|
|
+ return cal.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getTodayStr
|
|
|
|
|
+ * @Description: 获取今天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:21:51
|
|
|
|
|
+ * @param: @param pattern
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getTodayStr(String pattern) {
|
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat(pattern);
|
|
|
|
|
+
|
|
|
|
|
+ return format.format(getToday());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getTodayStr
|
|
|
|
|
+ * @Description: 获取今天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:33:22
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getTodayStr() {
|
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ return format.format(getToday());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getYesterdayStr
|
|
|
|
|
+ * @Description: 获取昨天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:21:11
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getYesterdayStr() {
|
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ return format.format(getYesterday());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getTomorrowStr
|
|
|
|
|
+ * @Description: 获取明天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:25:00
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getTomorrowStr() {
|
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ return format.format(getTomorrow());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: formatDate
|
|
|
|
|
+ * @Description: 格式化日期
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2018年1月4日 上午9:30:29
|
|
|
|
|
+ * @param: @param format
|
|
|
|
|
+ * @param: @param date
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String formatDate(Date date) {
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ return dateFormat.format(date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String formatDate(LocalDate date) {
|
|
|
|
|
+ return dateFormatter.format(date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: formatDateTime
|
|
|
|
|
+ * @Description: 格式化整个日期时间
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2018年6月25日 下午1:30:24
|
|
|
|
|
+ * @param: @param date
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String formatDateTime(Date date) {
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+ return dateFormat.format(date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String formatDateTime(LocalDateTime dateTime) {
|
|
|
|
|
+ return dateTimeFormatter.format(dateTime);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: parseDate
|
|
|
|
|
+ * @Description: 格式化日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:40:06
|
|
|
|
|
+ * @param: @param dateString
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @param: @throws ParseException
|
|
|
|
|
+ * @return: Date
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Date parseDate(String dateString) throws ParseException {
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ return dateFormat.parse(dateString);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: parseDateTime
|
|
|
|
|
+ * @Description: 格式化时间字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午7:40:24
|
|
|
|
|
+ * @param: @param dateString
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @param: @throws ParseException
|
|
|
|
|
+ * @return: Date
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Date parseDateTime(String dateString) throws ParseException {
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+ return dateFormat.parse(dateString);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getFewDateStrsByDate
|
|
|
|
|
+ * @Description: 获取近几天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午8:26:40
|
|
|
|
|
+ * @param: @param date
|
|
|
|
|
+ * @param: @param num
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getFewDateStrsByDate(Date date, int num) {
|
|
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
|
|
+
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+
|
|
|
|
|
+ cal.add(Calendar.DATE, -(num - 1));
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < num - 1; i++) {
|
|
|
|
|
+ cal.add(Calendar.DATE, 1);
|
|
|
|
|
+
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //去掉最后的逗号
|
|
|
|
|
+
|
|
|
|
|
+ return str.substring(0, str.length() - 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getFewDateStrsByWeek
|
|
|
|
|
+ * @Description: 获取近几周同一天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午8:33:23
|
|
|
|
|
+ * @param: @param date
|
|
|
|
|
+ * @param: @param num
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getFewDateStrsByWeek(Date date, int num) {
|
|
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
|
|
+
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+
|
|
|
|
|
+ cal.add(Calendar.WEEK_OF_YEAR, -(num - 1));
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < num - 1; i++) {
|
|
|
|
|
+ cal.add(Calendar.WEEK_OF_YEAR, 1);
|
|
|
|
|
+
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //去掉最后的逗号
|
|
|
|
|
+
|
|
|
|
|
+ return str.substring(0, str.length() - 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Title: getFewDateStrsByMonth
|
|
|
|
|
+ * @Description: 获取近几月同一天的日期字符串
|
|
|
|
|
+ * @author: 施勇
|
|
|
|
|
+ * @date: 2019年1月17日 上午8:31:31
|
|
|
|
|
+ * @param: @param date
|
|
|
|
|
+ * @param: @param num
|
|
|
|
|
+ * @param: @return
|
|
|
|
|
+ * @return: String
|
|
|
|
|
+ * @throws
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getFewDateStrsByMonth(Date date, int num) {
|
|
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
|
|
+
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+
|
|
|
|
|
+ cal.add(Calendar.MONTH, -(num - 1));
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < num - 1; i++) {
|
|
|
|
|
+ cal.add(Calendar.MONTH, 1);
|
|
|
|
|
+
|
|
|
|
|
+ str.append(formatDate(cal.getTime()) + ",");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //去掉最后的逗号
|
|
|
|
|
+
|
|
|
|
|
+ return str.substring(0, str.length() - 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取时间戳
|
|
* 获取时间戳
|
|
|
* @author shiyong
|
|
* @author shiyong
|
|
|
* 2019-10-09 13:36
|
|
* 2019-10-09 13:36
|
|
@@ -335,8 +338,8 @@ public class DateUtils {
|
|
|
public static long getTimeStamp() {
|
|
public static long getTimeStamp() {
|
|
|
return System.currentTimeMillis();
|
|
return System.currentTimeMillis();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
- System.out.println(getFewDateStrsByMonth(getToday(), 7));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ System.out.println(getFewDateStrsByMonth(getToday(), 7));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|