From a29a8d00dd9bbcde53814119ad4a081f3b4c6740 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Mon, 06 Sep 2021 13:24:28 +0800
Subject: [PATCH] screen-manage 插入设备的时候,判断组织是否含有型号并且添加默认报警值
---
screen-common/src/main/java/com/moral/util/DateUtils.java | 2485 +++++++++++++++++++++++++++++++---------------------------
1 files changed, 1,325 insertions(+), 1,160 deletions(-)
diff --git a/screen-common/src/main/java/com/moral/util/DateUtils.java b/screen-common/src/main/java/com/moral/util/DateUtils.java
index 9f5ea52..9af501f 100644
--- a/screen-common/src/main/java/com/moral/util/DateUtils.java
+++ b/screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -1,7 +1,7 @@
package com.moral.util;
-
+import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
@@ -14,1255 +14,1420 @@
import java.time.ZonedDateTime;
import java.util.*;
-
+@Slf4j
public class DateUtils {
- /** ������������(yyyy-MM-dd) */
- public static final String yyyy_MM_dd_EN = "yyyy-MM-dd";
- /** ������������(yyyy/MM/dd) */
- public static final String yyyy_MM_dd_decline = "yyyy/MM/dd";
- /** ������������(yyyyMMdd) */
- public static final String yyyyMMdd_EN = "yyyyMMdd";
- /** ������������(yyyy-MM) */
- public static final String yyyy_MM_EN = "yyyy-MM";
- /** ������������(yyyyMM) */
- public static final String yyyyMM_EN = "yyyyMM";
- /** ������������(yyyy-MM-dd HH:mm:ss) */
- public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss";
- /** ������������(yyyy-MM-dd HH:mm:ss.S) */
- public static final String yyyy_MM_dd_HH_mm_ss_S_EN = "yyyy-MM-dd HH:mm:ss.S";
- /** ������������(yyyyMMddHHmmss) */
- public static final String yyyyMMddHHmmss_EN = "yyyyMMddHHmmss";
- /** ������������(yyyy���MM���dd���) */
- public static final String yyyy_MM_dd_CN = "yyyy���MM���dd���";
- /** ������������(yyyy���MM���dd���HH���mm���ss���) */
- public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy���MM���dd���HH���mm���ss���";
- /** ������������(yyyy���MM���dd���HH���mm���) */
- public static final String yyyy_MM_dd_HH_mm_CN = "yyyy���MM���dd���HH���mm���";
- /** ������boss��������������������������������� */
- public static final String BJBOSS_DATE = "yyyy-MM-dd'T'HH:mm:ss'Z'";
- /** ������������(HH:mm:ss) */
- public static final String HH_mm_ss_EN = "HH:mm:ss";
- /** DateFormat������ */
- private static Map<String, DateFormat> dateFormatMap = new HashMap<String, DateFormat>();
+ /**
+ * ������������(yyyy)
+ */
+ public static final String yyyy = "yyyy";
+ /**
+ * ������������(yyyy-MM-dd)
+ */
+ public static final String yyyy_MM_dd_EN = "yyyy-MM-dd";
+ /**
+ * ������������(yyyy/MM/dd)
+ */
+ public static final String yyyy_MM_dd_decline = "yyyy/MM/dd";
+ /**
+ * ������������(yyyyMMdd)
+ */
+ public static final String yyyyMMdd_EN = "yyyyMMdd";
+ /**
+ * ������������(yyyy-MM)
+ */
+ public static final String yyyy_MM_EN = "yyyy-MM";
+ /**
+ * ������������(yyyyMM)
+ */
+ public static final String yyyyMM_EN = "yyyyMM";
+ /**
+ * ������������(yyyy-MM-dd HH:mm:ss)
+ */
+ public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss";
+ /**
+ * ������������(yyyy-MM-dd HH:mm:ss.S)
+ */
+ public static final String yyyy_MM_dd_HH_mm_ss_S_EN = "yyyy-MM-dd HH:mm:ss.S";
+ /**
+ * ������������(yyyyMMddHHmmss)
+ */
+ public static final String yyyyMMddHHmmss_EN = "yyyyMMddHHmmss";
+ /**
+ * ������������(yyyy���MM���dd���)
+ */
+ public static final String yyyy_MM_dd_CN = "yyyy���MM���dd���";
+ /**
+ * ������������(yyyy���MM���dd���HH���mm���ss���)
+ */
+ public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy���MM���dd���HH���mm���ss���";
+ /**
+ * ������������(yyyy���MM���dd���HH���mm���)
+ */
+ public static final String yyyy_MM_dd_HH_mm_CN = "yyyy���MM���dd���HH���mm���";
+ /**
+ * ������boss���������������������������������
+ */
+ public static final String BJBOSS_DATE = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+ /**
+ * ������������(HH:mm:ss)
+ */
+ public static final String HH_mm_ss_EN = "HH:mm:ss";
+ /*
+ * ������������(yyyy-MM-dd HH:mm)
+ * */
+ public static final String yyyy_MM_dd_HH_mm_EN = "yyyy-MM-dd HH:mm";
+ /*
+ * ������������(yyyy-MM-dd HH)
+ * */
+ public static final String yyyy_MM_dd_HH_EN = "yyyy-MM-dd HH";
+ /*
+ * Date���toString������
+ * */
+ public static final String EEE_MMM_dd_HH_mm_ss_zzz_yyyy = "EEE MMM dd HH:mm:ss zzz yyyy";
+ /**
+ * DateFormat������
+ */
+ private static Map<String, DateFormat> dateFormatMap = new HashMap<String, DateFormat>();
- /**
- * ������DateFormat
- *
- * @param formatStr
- * @return
- */
- public static DateFormat getDateFormat(String formatStr) {
- DateFormat df = dateFormatMap.get(formatStr);
- if (df == null) {
- df = new SimpleDateFormat(formatStr);
- dateFormatMap.put(formatStr, df);
- }
- return df;
- }
+ /**
+ * @Description: Date���toString������������Date
+ * @Param: []
+ * @return: java.util.Date
+ * @Author: ���������
+ * @Date: 2021/8/25
+ */
+ public static Date dateStringToDate(String formatStr){
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat(EEE_MMM_dd_HH_mm_ss_zzz_yyyy, Locale.US);
+ return sdf.parse(formatStr);
+ } catch (ParseException e) {
+ log.error(e.getMessage());
+ return null;
+ }
+ }
- public static Date getDate() {
- return Calendar.getInstance().getTime();
- }
+ /**
+ * ������DateFormat
+ *
+ * @param formatStr
+ * @return
+ */
+ public static DateFormat getDateFormat(String formatStr) {
+ DateFormat df = dateFormatMap.get(formatStr);
+ if (df == null) {
+ df = new SimpleDateFormat(formatStr);
+ dateFormatMap.put(formatStr, df);
+ }
+ return df;
+ }
- /**
- * ������������formatStr������������������dateTimeStr���Date������ dateTimeStr���������formatStr���������
- *
- * @param dateTimeStr
- * @param formatStr
- * @return
- */
- public static Date getDate(String dateTimeStr, String formatStr) {
- try {
- if (dateTimeStr == null || dateTimeStr.equals("")) {
- return null;
- }
- DateFormat sdf = getDateFormat(formatStr);
- return sdf.parse(dateTimeStr);
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }
+ public static Date getDate() {
+ return Calendar.getInstance().getTime();
+ }
- /**
- * ������dateTimeStr���Date������
- *
- * @param dateTimeStr
- * @return
- */
- public static Date convertDate(String dateTimeStr) {
- try {
- if (dateTimeStr == null || dateTimeStr.equals("")) {
- return null;
- }
- DateFormat sdf = getDateFormat(yyyy_MM_dd_EN);
- Date d = sdf.parse(dateTimeStr);
- return d;
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }
+ /**
+ * ������������formatStr������������������dateTimeStr���Date������ dateTimeStr���������formatStr���������
+ *
+ * @param dateTimeStr
+ * @param formatStr
+ * @return
+ */
+ public static Date getDate(String dateTimeStr, String formatStr) {
+ try {
+ if (dateTimeStr == null || dateTimeStr.equals("")) {
+ return null;
+ }
+ DateFormat sdf = getDateFormat(formatStr);
+ return sdf.parse(dateTimeStr);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * ���������������������������������������"yyyy-MM-dd"���������dateTimeStr���Date������ dateTimeStr���������"yyyy-MM-dd"���������
- *
- * @param dateTimeStr
- * @return
- */
- public static Date getDate(String dateTimeStr) {
- return getDate(dateTimeStr, yyyy_MM_dd_EN);
- }
+ /**
+ * ������dateTimeStr���Date������
+ *
+ * @param dateTimeStr
+ * @return
+ */
+ public static Date convertDate(String dateTimeStr) {
+ try {
+ if (dateTimeStr == null || dateTimeStr.equals("")) {
+ return null;
+ }
+ DateFormat sdf = getDateFormat(yyyy_MM_dd_EN);
+ Date d = sdf.parse(dateTimeStr);
+ return d;
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * ���YYYYMMDD���������Date������
- *
- * @param date
- * @return
- * @throws Exception
- */
- public static Date transferDate(String date) throws Exception {
- if (date == null || date.length() < 1)
- return null;
+ /**
+ * ���������������������������������������"yyyy-MM-dd"���������dateTimeStr���Date������ dateTimeStr���������"yyyy-MM-dd"���������
+ *
+ * @param dateTimeStr
+ * @return
+ */
+ public static Date getDate(String dateTimeStr) {
+ return getDate(dateTimeStr, yyyy_MM_dd_EN);
+ }
- if (date.length() != 8)
- throw new Exception("������������������");
- String con = "-";
+ /**
+ * ���YYYYMMDD���������Date������
+ *
+ * @param date
+ * @return
+ * @throws Exception
+ */
+ public static Date transferDate(String date) throws Exception {
+ if (date == null || date.length() < 1)
+ return null;
- String yyyy = date.substring(0, 4);
- String mm = date.substring(4, 6);
- String dd = date.substring(6, 8);
+ if (date.length() != 8)
+ throw new Exception("������������������");
+ String con = "-";
- int month = Integer.parseInt(mm);
- int day = Integer.parseInt(dd);
- if (month < 1 || month > 12 || day < 1 || day > 31)
- throw new Exception("������������������");
+ String yyyy = date.substring(0, 4);
+ String mm = date.substring(4, 6);
+ String dd = date.substring(6, 8);
- String str = yyyy + con + mm + con + dd;
- return getDate(str, yyyy_MM_dd_EN);
- }
+ int month = Integer.parseInt(mm);
+ int day = Integer.parseInt(dd);
+ if (month < 1 || month > 12 || day < 1 || day > 31)
+ throw new Exception("������������������");
- /**
- * ���Date���������������������yyyy-mm-dd hh:mm:ss���������������
- *
- * @param date
- * @return
- */
- public static String dateToDateString(Date date) {
- return dateToDateString(date, yyyy_MM_dd_HH_mm_ss_EN);
- }
+ String str = yyyy + con + mm + con + dd;
+ return getDate(str, yyyy_MM_dd_EN);
+ }
- /**
- * ���Date���������������������yyyymmddhhmmss���������������
- *
- * @param date
- * @return
- */
- public static String dateToDateFullString(Date date) {
- if (null == date)
- return null;
- else
- return dateToDateString(date, yyyyMMddHHmmss_EN);
- }
+ /**
+ * ���Date���������������������yyyy-mm-dd hh:mm:ss���������������
+ *
+ * @param date
+ * @return
+ */
+ public static String dateToDateString(Date date) {
+ return dateToDateString(date, yyyy_MM_dd_HH_mm_ss_EN);
+ }
- /**
- * ���Date���������formatStr������������������
- *
- * @param date
- * @param formatStr
- * @return
- */
- public static String dateToDateString(Date date, String formatStr) {
- DateFormat df = getDateFormat(formatStr);
- return df.format(date);
- }
+ /**
+ * ���Date���������������������yyyymmddhhmmss���������������
+ *
+ * @param date
+ * @return
+ */
+ public static String dateToDateFullString(Date date) {
+ if (null == date)
+ return null;
+ else
+ return dateToDateString(date, yyyyMMddHHmmss_EN);
+ }
- /**
- * ���String���������formatStr������������������
- *
- * @param date
- * @param formatStr1
- * @param formatStr2
- * @return
- */
- public static String stringToDateString(String date, String formatStr1, String formatStr2) {
- Date d = getDate(date, formatStr1);
- DateFormat df = getDateFormat(formatStr2);
- return df.format(d);
- }
+ /**
+ * ���Date���������formatStr������������������
+ *
+ * @param date
+ * @param formatStr
+ * @return
+ */
+ public static String dateToDateString(Date date, String formatStr) {
+ DateFormat df = getDateFormat(formatStr);
+ return df.format(date);
+ }
- /**
- * ������������������yyyy-MM-dd���������
- *
- * @return
- */
- public static String getCurDate() {
- return dateToDateString(new Date(), yyyy_MM_dd_EN);
- }
+ /**
+ * ���String���������formatStr������������������
+ *
+ * @param date
+ * @param formatStr1
+ * @param formatStr2
+ * @return
+ */
+ public static String stringToDateString(String date, String formatStr1, String formatStr2) {
+ Date d = getDate(date, formatStr1);
+ DateFormat df = getDateFormat(formatStr2);
+ return df.format(d);
+ }
- /**
- * ������������������
- *
- * @return
- */
- public static String getCurDate(String formatStr) {
- return dateToDateString(new Date(), formatStr);
- }
+ /**
+ * ������������������yyyy-MM-dd���������
+ *
+ * @return
+ */
+ public static String getCurDate() {
+ return dateToDateString(new Date(), yyyy_MM_dd_EN);
+ }
- /**
- * ������������������yyyy���MM���dd������������
- *
- * @return
- */
- public static String getCurCNDate() {
- return dateToDateString(new Date(), yyyy_MM_dd_CN);
- }
+ /**
+ * ������������������
+ *
+ * @return
+ */
+ public static String getCurDate(String formatStr) {
+ return dateToDateString(new Date(), formatStr);
+ }
- /**
- * ������������������������yyyy-MM-dd HH:mm:ss���������
- *
- * @return
- */
- public static String getCurDateTime() {
- return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_EN);
- }
+ /**
+ * ������������������yyyy���MM���dd������������
+ *
+ * @return
+ */
+ public static String getCurCNDate() {
+ return dateToDateString(new Date(), yyyy_MM_dd_CN);
+ }
- /**
- * ������������������������yyyy���MM���dd���HH���mm���ss������������
- *
- * @return
- */
- public static String getCurZhCNDateTime() {
- return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_CN);
- }
+ /**
+ * ������������������������yyyy-MM-dd HH:mm:ss���������
+ *
+ * @return
+ */
+ public static String getCurDateTime() {
+ return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_EN);
+ }
- /**
- * ������������"yyyy-MM-dd HH:mm:ss"������������������������������������������,time2-time1
- *
- * @param time1
- * @param time2
- * @return
- */
- public static long compareDateStr(String time1, String time2) {
- Date d1 = getDate(time1);
- Date d2 = getDate(time2);
- return d2.getTime() - d1.getTime();
- }
+ /**
+ * ������������������������yyyy���MM���dd���HH���mm���ss������������
+ *
+ * @return
+ */
+ public static String getCurZhCNDateTime() {
+ return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_CN);
+ }
- /**
- * ���������������������������������������
- *
- * @param time1
- * @param time2
- * @param format
- * @return
- */
- public static long compareDateStr(String time1, String time2, String format) {
- Date d1 = getDate(time1, format);
- Date d2 = getDate(time2, format);
- return d2.getTime() - d1.getTime();
- }
+ /**
+ * ������������"yyyy-MM-dd HH:mm:ss"������������������������������������������,time2-time1
+ *
+ * @param time1
+ * @param time2
+ * @return
+ */
+ public static long compareDateStr(String time1, String time2) {
+ Date d1 = getDate(time1);
+ Date d2 = getDate(time2);
+ return d2.getTime() - d1.getTime();
+ }
- /**
- * ������������������������������������������������
- *
- * @param time
- * @param format
- * @return
- */
- public static long compareDateNow(String time, String format) {
- Date date = getDate(time, format);
- return new Date().getTime() - date.getTime();
- }
+ /**
+ * ���������������������������������������
+ *
+ * @param time1
+ * @param time2
+ * @param format
+ * @return
+ */
+ public static long compareDateStr(String time1, String time2, String format) {
+ Date d1 = getDate(time1, format);
+ Date d2 = getDate(time2, format);
+ return d2.getTime() - d1.getTime();
+ }
- /**
- * ������������"yyyy-MM-dd HH:mm:ss"������������������������������������������,time2-time1
- *
- * @param time1
- * @param time2
- * @return
- */
- public static long compareDateStr(Date time1, Date time2) {
- return time2.getTime() - time1.getTime();
- }
+ /**
+ * ������������������������������������������������
+ *
+ * @param time
+ * @param format
+ * @return
+ */
+ public static long compareDateNow(String time, String format) {
+ Date date = getDate(time, format);
+ return new Date().getTime() - date.getTime();
+ }
- /**
- * nows������������date������ ���true
- *
- * @param nows
- * @param date
- * @return
- */
- public static boolean isTimeBefor(Date nows, Date date) {
- long hous = nows.getTime() - date.getTime();
- if (hous > 0) {
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * ������������"yyyy-MM-dd HH:mm:ss"������������������������������������������,time2-time1
+ *
+ * @param time1
+ * @param time2
+ * @return
+ */
+ public static long compareDateStr(Date time1, Date time2) {
+ return time2.getTime() - time1.getTime();
+ }
- /**
- * ������������������������������������������������������
- *
- * @param hours
- * @return
- */
- public static long getMicroSec(BigDecimal hours) {
- BigDecimal bd;
- bd = hours.multiply(new BigDecimal(3600 * 1000));
- return bd.longValue();
- }
+ /**
+ * nows������������date������ ���true
+ *
+ * @param nows
+ * @param date
+ * @return
+ */
+ public static boolean isTimeBefor(Date nows, Date date) {
+ long hous = nows.getTime() - date.getTime();
+ if (hous > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * ������������������years���������������(formatStr)������������
- *
- * @param years
- * @param formatStr
- * @return
- */
- public static String getDateStringOfYear(int years, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.YEAR, years);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������������������������������������������
+ *
+ * @param hours
+ * @return
+ */
+ public static long getMicroSec(BigDecimal hours) {
+ BigDecimal bd;
+ bd = hours.multiply(new BigDecimal(3600 * 1000));
+ return bd.longValue();
+ }
- /**
- * ������������������mon���������������(formatStr)������������
- *
- * @param months
- * @param formatStr
- * @return
- */
- public static String getDateStringOfMon(int months, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.MONTH, months);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������years���������������(formatStr)������������
+ *
+ * @param years
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfYear(int years, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.YEAR, years);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ������������������days���������������(formatStr)������������
- *
- * @param days
- * @param formatStr
- * @return
- */
- public static String getDateStringOfDay(int days, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.DATE, days);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������mon���������������(formatStr)������������
+ *
+ * @param months
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfMon(int months, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.MONTH, months);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ���������������������������
- *
- * @param date
- * @return
- */
- public static int theDateIsToday(String date, String format) {
- String theDate = stringToDateString(date, format, yyyyMMdd_EN);
- String today = getDateStringOfDay(0, yyyyMMdd_EN);
- if (theDate.equals(today)) {
- return 1;
- } else {
- return 0;
- }
- }
+ /**
+ * ������������������days���������������(formatStr)������������
+ *
+ * @param days
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfDay(int days, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.DATE, days);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ������������������hours������������������(formatStr)������������
- *
- * @param hours
- * @param formatStr
- * @return
- */
- public static String getDateStringOfHour(int hours, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.HOUR_OF_DAY, hours);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ���������������������������
+ *
+ * @param date
+ * @return
+ */
+ public static int theDateIsToday(String date, String format) {
+ String theDate = stringToDateString(date, format, yyyyMMdd_EN);
+ String today = getDateStringOfDay(0, yyyyMMdd_EN);
+ if (theDate.equals(today)) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
- /**
- * ������������������mon���������������(formatStr)������������
- *
- * @param date
- * @param mon
- * @param formatStr
- * @return
- */
- public static String getDateOfMon(String date, int mon, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(getDate(date, formatStr));
- now.add(Calendar.MONTH, mon);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������hours������������������(formatStr)������������
+ *
+ * @param hours
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfHour(int hours, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.HOUR_OF_DAY, hours);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ������������������day���������������(formatStr)������������
- *
- * @param date
- * @param day
- * @param formatStr
- * @return
- */
- public static String getDateOfDay(String date, int day, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(getDate(date, formatStr));
- now.add(Calendar.DATE, day);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������mon���������������(formatStr)������������
+ *
+ * @param date
+ * @param mon
+ * @param formatStr
+ * @return
+ */
+ public static String getDateOfMon(String date, int mon, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(getDate(date, formatStr));
+ now.add(Calendar.MONTH, mon);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- public static Date getDate(Date beginDate, int ds) {
- if (ds == 0)
- return new Date();
- try {
- SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
- Calendar date = Calendar.getInstance();
- date.setTime(beginDate);
- date.set(Calendar.DATE, date.get(Calendar.DATE) - ds);
- Date endDate = dft.parse(dft.format(date.getTime()));
- return endDate;
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return new Date();
- }
+ /**
+ * ������������������day���������������(formatStr)������������
+ *
+ * @param date
+ * @param day
+ * @param formatStr
+ * @return
+ */
+ public static String getDateOfDay(String date, int day, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(getDate(date, formatStr));
+ now.add(Calendar.DATE, day);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- public static String getAfterNDays(Date date, int n, String formateStr) {
- SimpleDateFormat sdf = new SimpleDateFormat(formateStr);
- Calendar calendar = new GregorianCalendar();
- calendar.setTime(date);
- calendar.add(Calendar.DATE, n);
- return sdf.format(calendar.getTime());
- }
+ /**
+ * @Description: ������������������day���������������
+ * @Param: [date, day]
+ * @return: java.util.Date
+ * @Author: ���������
+ * @Date: 2021/3/30
+ */
+ public static Date getDateOfDay(Date date, int day) {
+ if (date == null)
+ return null;
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(date);
+ now.add(Calendar.DAY_OF_MONTH, day);
+ return now.getTime();
+ }
- /**
- * ������������������mins������������������(formatStr)������������
- *
- * @param date
- * @param mins
- * @param formatStr
- * @return
- */
- public static String getDateOfMin(String date, int mins, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(getDate(date, formatStr));
- now.add(Calendar.SECOND, mins * 60);
- return dateToDateString(now.getTime(), formatStr);
- }
- /**
- * ������������������mins������������������������
- *
- * @param date
- * @param mins
- * @return
- */
- public static Date getDateOfMin(Date date, int mins) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(date);
- now.add(Calendar.SECOND, mins * 60);
- return now.getTime();
- }
+ public static Date getDate(Date beginDate, int ds) {
+ if (ds == 0)
+ return new Date();
+ try {
+ SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar date = Calendar.getInstance();
+ date.setTime(beginDate);
+ date.set(Calendar.DATE, date.get(Calendar.DATE) - ds);
+ Date endDate = dft.parse(dft.format(date.getTime()));
+ return endDate;
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return new Date();
+ }
- /**
- * ������������������mins������������������(formatStr)������������
- *
- * @param mins
- * @param formatStr
- * @return
- */
- public static String getDateStringOfMin(int mins, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.MINUTE, mins);
- return dateToDateString(now.getTime(), formatStr);
- }
+ public static String getAfterNDays(Date date, int n, String formateStr) {
+ SimpleDateFormat sdf = new SimpleDateFormat(formateStr);
+ Calendar calendar = new GregorianCalendar();
+ calendar.setTime(date);
+ calendar.add(Calendar.DATE, n);
+ return sdf.format(calendar.getTime());
+ }
- /**
- * ������������������mins������������������������
- *
- * @param mins
- * @return
- */
- public static Date getDateOfMin(int mins) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.MINUTE, mins);
- return now.getTime();
- }
+ /**
+ * ������������������mins������������������(formatStr)������������
+ *
+ * @param date
+ * @param mins
+ * @param formatStr
+ * @return
+ */
+ public static String getDateOfMin(String date, int mins, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(getDate(date, formatStr));
+ now.add(Calendar.SECOND, mins * 60);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ������������������sec���������������(formatStr)������������
- *
- * @param sec
- * @param formatStr
- * @return
- */
- public static String getDateStringOfSec(int sec, String formatStr) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(new Date());
- now.add(Calendar.SECOND, sec);
- return dateToDateString(now.getTime(), formatStr);
- }
+ /**
+ * ������������������mins������������������������
+ *
+ * @param date
+ * @param mins
+ * @return
+ */
+ public static Date getDateOfMin(Date date, int mins) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(date);
+ now.add(Calendar.SECOND, mins * 60);
+ return now.getTime();
+ }
- /**
- * ���������������������������������
- *
- * @return
- */
- public static int getMonthDay(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- return c.getActualMaximum(Calendar.DAY_OF_MONTH);
+ /**
+ * ������������������mins������������������(formatStr)������������
+ *
+ * @param mins
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfMin(int mins, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.MINUTE, mins);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- }
+ /**
+ * ������������������mins������������������������
+ *
+ * @param mins
+ * @return
+ */
+ public static Date getDateOfMin(int mins) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.MINUTE, mins);
+ return now.getTime();
+ }
- /**
- * ���������������������������������
- *
- * @return
- */
- public static int getCurentMonthDay() {
- Date date = Calendar.getInstance().getTime();
- return getMonthDay(date);
- }
+ /**
+ * ������������������sec���������������(formatStr)������������
+ *
+ * @param sec
+ * @param formatStr
+ * @return
+ */
+ public static String getDateStringOfSec(int sec, String formatStr) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(new Date());
+ now.add(Calendar.SECOND, sec);
+ return dateToDateString(now.getTime(), formatStr);
+ }
- /**
- * ��������������������������������� yyyy-mm-dd
- *
- * @return
- */
- public static int getMonthDay(String date) {
- Date strDate = getDate(date, yyyy_MM_dd_EN);
- return getMonthDay(strDate);
- }
+ /**
+ * ���������������������������������
+ *
+ * @return
+ */
+ public static int getMonthDay(Date date) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ return c.getActualMaximum(Calendar.DAY_OF_MONTH);
- /**
- * ������19xx,20xx������������
- *
- * @param d
- * @return
- */
- public static int getYear(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.YEAR);
- }
+ }
- /**
- * ���������������1-12���
- *
- * @param d
- * @return
- */
- public static int getMonth(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.MONTH) + 1;
- }
+ /**
+ * ���������������������������������
+ *
+ * @return
+ */
+ public static int getCurentMonthDay() {
+ Date date = Calendar.getInstance().getTime();
+ return getMonthDay(date);
+ }
- /**
- * ������xxxx-xx-xx������
- *
- * @param d
- * @return
- */
- public static int getDay(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.DAY_OF_MONTH);
- }
+ /**
+ * ��������������������������������� yyyy-mm-dd
+ *
+ * @return
+ */
+ public static int getMonthDay(String date) {
+ Date strDate = getDate(date, yyyy_MM_dd_EN);
+ return getMonthDay(strDate);
+ }
- /**
- * ������Date������������(24������)
- *
- * @param d
- * @return
- */
- public static int getHour(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.HOUR_OF_DAY);
- }
+ /**
+ * ������19xx,20xx������������
+ *
+ * @param d
+ * @return
+ */
+ public static int getYear(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.YEAR);
+ }
+
+ /**
+ * ���������������1-12���
+ *
+ * @param d
+ * @return
+ */
+ public static int getMonth(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.MONTH) + 1;
+ }
+
+ /**
+ * ������xxxx-xx-xx������
+ *
+ * @param d
+ * @return
+ */
+ public static int getDay(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.DAY_OF_MONTH);
+ }
+
+ /**
+ * ������Date������������(24������)
+ *
+ * @param d
+ * @return
+ */
+ public static int getHour(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.HOUR_OF_DAY);
+ }
+
+ /**
+ * ������Date������������
+ *
+ * @param d
+ * @return
+ */
+ public static int getMin(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.MINUTE);
+ }
+
+ /**
+ * ������Date���������
+ *
+ * @param d
+ * @return
+ */
+ public static int getSecond(Date d) {
+ Calendar now = Calendar.getInstance(TimeZone.getDefault());
+ now.setTime(d);
+ return now.get(Calendar.SECOND);
+ }
+
+ /**
+ * ������������������
+ *
+ * @return yyyy-MM-dd
+ */
+ public static String getMondayOfThisWeek() {
+ Calendar c = Calendar.getInstance();
+ int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
+ if (day_of_week == 0)
+ day_of_week = 7;
+ c.add(Calendar.DATE, -day_of_week + 1);
+ return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
+ }
+
+ /**
+ * ������������������
+ *
+ * @return yyyy-MM-dd
+ */
+ public static String getSundayOfThisWeek() {
+ Calendar c = Calendar.getInstance();
+ int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
+ if (day_of_week == 0)
+ day_of_week = 7;
+ c.add(Calendar.DATE, -day_of_week + 7);
+ return dateToDateString(c.getTime());
+ }
+
+ /**
+ * ���������������(*)
+ *
+ * @return yyyy-MM-dd
+ */
+ public static String getDayOfThisWeek(int num) {
+ Calendar c = Calendar.getInstance();
+ int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
+ if (day_of_week == 0)
+ day_of_week = 7;
+ c.add(Calendar.DATE, -day_of_week + num);
+ return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
+ }
+
+ /**
+ * ���������������������
+ *
+ * @return yyyy-MM-dd
+ */
+ public static String getDayOfThisMoon(String num) {
+ String date = dateToDateString(new Date(), yyyy_MM_EN);
+ date = date + "-" + num;
+ return date;
+ }
+
+ /**
+ * ���������������������������������
+ *
+ * @param beginDate
+ * @param endDate
+ * @return
+ */
+ public static long getQuotByDays(String beginDate, String endDate) {
+ long quot = 0;
+ DateFormat df = getDateFormat(yyyy_MM_dd_EN);
+ try {
+ Date d1 = df.parse(beginDate);
+ Date d2 = df.parse(endDate);
+ quot = d2.getTime() - d1.getTime();
+ quot = quot / 1000 / 60 / 60 / 24;
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ return quot;
+ }
+
+ /**
+ * ���������������������������������������������������
+ *
+ * @param date
+ * @param days
+ * @return
+ */
+ public static String getDateAddDay(String date, int days) {
+ DateFormat df = getDateFormat(yyyy_MM_dd_EN);
+ try {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(df.parse(date));
+ cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + days);
+
+ date = df.format(cal.getTime());
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ return date;
+ }
+
+ /**
+ * ������������������������
+ *
+ * @return
+ */
+ public static Date getFirstDayOfCurrMonth() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
+ }
- /**
- * ������Date������������
- *
- * @param d
- * @return
- */
- public static int getMin(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.MINUTE);
- }
+ /**
+ * ������������������������������
+ *
+ * @return
+ */
+ public static Date getLastDayOfCurrMonth() {
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.MONTH, 1);
+ cal.set(Calendar.DAY_OF_MONTH, 0);
+ return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
+ }
- /**
- * ������Date���������
- *
- * @param d
- * @return
- */
- public static int getSecond(Date d) {
- Calendar now = Calendar.getInstance(TimeZone.getDefault());
- now.setTime(d);
- return now.get(Calendar.SECOND);
- }
+ /**
+ * ���������������������������������������������������
+ *
+ * @param date
+ * @param m
+ * @return
+ */
+ public static String getDateAddMonth(String date, int m) {
+ DateFormat df = getDateFormat(yyyy_MM_EN);
+ try {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(df.parse(date));
+ cal.add(Calendar.MONTH, m);
+ date = df.format(cal.getTime());
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ return date;
+ }
- /**
- * ������������������
- *
- * @return yyyy-MM-dd
- */
- public static String getMondayOfThisWeek() {
- Calendar c = Calendar.getInstance();
- int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
- if (day_of_week == 0)
- day_of_week = 7;
- c.add(Calendar.DATE, -day_of_week + 1);
- return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
- }
+ /**
+ * ������������������������������
+ *
+ * @param year
+ * @param month
+ * @return
+ */
+ public static String getFirstDayOfMonth(int year, int month) {
+ Calendar cal = Calendar.getInstance();
+ // ������������
+ cal.set(Calendar.YEAR, year);
+ // ������������
+ cal.set(Calendar.MONTH, month - 1);
+ // ������������������������
+ int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
+ // ������������������������������������
+ cal.set(Calendar.DAY_OF_MONTH, lastDay);
+ // ���������������
+ DateFormat df = getDateFormat(yyyy_MM_dd_EN);
+ return df.format(cal.getTime());
+ }
- /**
- * ������������������
- *
- * @return yyyy-MM-dd
- */
- public static String getSundayOfThisWeek() {
- Calendar c = Calendar.getInstance();
- int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
- if (day_of_week == 0)
- day_of_week = 7;
- c.add(Calendar.DATE, -day_of_week + 7);
- return dateToDateString(c.getTime());
- }
+ /**
+ * ������������������������������
+ *
+ * @param year
+ * @param month
+ * @return
+ */
+ public static String getLastDayOfMonth(int year, int month) {
+ Calendar cal = Calendar.getInstance();
+ // ������������
+ cal.set(Calendar.YEAR, year);
+ // ������������
+ cal.set(Calendar.MONTH, month - 1);
+ // ������������������������
+ int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+ // ������������������������������������
+ cal.set(Calendar.DAY_OF_MONTH, lastDay);
+ // ���������������
+ DateFormat df = getDateFormat(yyyy_MM_dd_EN);
+ return df.format(cal.getTime());
+ }
- /**
- * ���������������(*)
- *
- * @return yyyy-MM-dd
- */
- public static String getDayOfThisWeek(int num) {
- Calendar c = Calendar.getInstance();
- int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
- if (day_of_week == 0)
- day_of_week = 7;
- c.add(Calendar.DATE, -day_of_week + num);
- return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
- }
+ /**
+ * ������������������
+ *
+ * @param date
+ * @return
+ * @throws ParseException
+ */
+ public static String getYesterday(Date date) throws ParseException {
+ DateFormat df = getDateFormat(yyyy_MM_dd_EN);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(df.parse(df.format(date)));
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ return df.format(calendar.getTime());
+ }
- /**
- * ���������������������
- *
- * @return yyyy-MM-dd
- */
- public static String getDayOfThisMoon(String num) {
- String date = dateToDateString(new Date(), yyyy_MM_EN);
- date = date + "-" + num;
- return date;
- }
- /**
- * ���������������������������������
- *
- * @param beginDate
- * @param endDate
- * @return
- */
- public static long getQuotByDays(String beginDate, String endDate) {
- long quot = 0;
- DateFormat df = getDateFormat(yyyy_MM_dd_EN);
- try {
- Date d1 = df.parse(beginDate);
- Date d2 = df.parse(endDate);
- quot = d2.getTime() - d1.getTime();
- quot = quot / 1000 / 60 / 60 / 24;
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- return quot;
- }
+ /**
+ * 10���������������������
+ *
+ * @param dateInt
+ * @param format
+ * @return
+ */
+ public static String getIntToStr(String dateInt, String format) {
+ DateFormat df = getDateFormat(format);
+ long times = Integer.parseInt(dateInt) * 1000L;
+ Date date = new Date(times);
+ return df.format(date);
+ }
- /**
- * ���������������������������������������������������
- *
- * @param date
- * @param days
- * @return
- */
- public static String getDateAddDay(String date, int days, String format) {
- DateFormat df = getDateFormat(format);
- try {
- Calendar cal = Calendar.getInstance();
- cal.setTime(df.parse(date));
- cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + days);
+ /**
+ * ������ 10������������
+ *
+ * @return
+ */
+ public static Integer getDateInt() {
+ return (int) (System.currentTimeMillis() / 1000);
+ }
- date = df.format(cal.getTime());
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- return date;
- }
+ /**
+ * 13���������������������
+ *
+ * @param time
+ * @param format
+ * @return
+ */
+ public static String getLongToStr(long time, String format) {
+ Date date = new Date(time);
+ return dateToDateString(date, format);
+ }
- /**
- * ������������������������������
- *
- * @return
- */
- public static Date getLastDayOfCurrMonth() {
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.MONTH, 1);
- cal.set(Calendar.DAY_OF_MONTH, 0);
+ /**
+ * ������������������������������������
+ *
+ * @param start
+ * @param end
+ * @return
+ */
+ public static int getIntervalSec(int start, int end) {
+ return (end - start) * 60 * 60;
+ }
- return cal.getTime();
- }
+ /**
+ * ���������������������������������
+ *
+ * @param time
+ * @return
+ */
+ public static String getMillsStr(long time) {
+ String timeStr = String.valueOf(time);
+ String suffix = timeStr.substring(0, timeStr.length() - 3);
+ String prefix = timeStr.substring(timeStr.length() - 3, timeStr.length());
+ return suffix + "." + prefix;
+ }
- /**
- * ���������������������������������������������������
- *
- * @param date
- * @param m
- * @return
- */
- public static String getDateAddMonth(String date, int m) {
- DateFormat df = getDateFormat(yyyyMM_EN);
- try {
- Calendar cal = Calendar.getInstance();
- cal.setTime(df.parse(date));
- cal.add(Calendar.MONTH, m);
- date = df.format(cal.getTime());
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- return date;
- }
+ /**
+ * ���������������������������������������������
+ *
+ * @param timeStr
+ * @param formatStr
+ * @return
+ */
+ public static String longToString(String timeStr, String formatStr) {
+ long times = Long.parseLong(timeStr.replace(".", ""));
+ Date date = new Date(times);
+ return dateToDateString(date, formatStr);
+ }
- /**
- * ������������������������������
- *
- * @param year
- * @param month
- * @return
- */
- public static String getFirstDayOfMonth(int year, int month) {
- Calendar cal = Calendar.getInstance();
- // ������������
- cal.set(Calendar.YEAR, year);
- // ������������
- cal.set(Calendar.MONTH, month - 1);
- // ������������������������
- int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
- // ������������������������������������
- cal.set(Calendar.DAY_OF_MONTH, lastDay);
- // ���������������
- DateFormat df = getDateFormat(yyyy_MM_dd_EN);
- return df.format(cal.getTime());
- }
+ /**
+ * ������������������������
+ *
+ * @return
+ */
+ public static Long getTodayTime() {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime();
+ }
- /**
- * ������������������������������
- *
- * @param year
- * @param month
- * @return
- */
- public static String getLastDayOfMonth(int year, int month) {
- Calendar cal = Calendar.getInstance();
- // ������������
- cal.set(Calendar.YEAR, year);
- // ������������
- cal.set(Calendar.MONTH, month - 1);
- // ������������������������
- int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
- // ������������������������������������
- cal.set(Calendar.DAY_OF_MONTH, lastDay);
- // ���������������
- DateFormat df = getDateFormat(yyyy_MM_dd_EN);
- return df.format(cal.getTime());
- }
+ public static Integer getTodayInt() {
+ return (int) (getTodayTime() / 1000);
+ }
- /**
- * ������������������
- *
- * @param date
- * @return
- * @throws ParseException
- */
- public static String getYesterday(Date date) throws ParseException {
- DateFormat df = getDateFormat(yyyy_MM_dd_EN);
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(df.parse(df.format(date)));
- calendar.add(Calendar.DAY_OF_MONTH, -1);
- return df.format(calendar.getTime());
- }
+ /**
+ * ������������������������
+ *
+ * @return
+ */
+ public static Long getEndTime() {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.set(Calendar.HOUR, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTime().getTime();
+ }
+ public static Integer getTomorrowInt() {
+ return (int) (getTomorrowTime() / 1000);
+ }
- /**
- * 10���������������������
- *
- * @param dateInt
- * @param format
- * @return
- */
- public static String getIntToStr(String dateInt, String format) {
- DateFormat df = getDateFormat(format);
- long times = Integer.parseInt(dateInt) * 1000L;
- Date date = new Date(times);
- return df.format(date);
- }
+ /**
+ * ���������������������������
+ *
+ * @return
+ */
+ public static Long getTomorrowTime() {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ cal.add(Calendar.DAY_OF_MONTH, 1);
+ return cal.getTime().getTime();
+ }
- /**
- * ������ 10������������
- *
- * @return
- */
- public static Integer getDateInt() {
- return (int) (System.currentTimeMillis() / 1000);
- }
+ /**
+ * ���������������������������������
+ *
+ * @param hour
+ * @return
+ */
+ public static Long getPointHourTime(int hour) {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.set(Calendar.HOUR_OF_DAY, hour);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime();
+ }
- /**
- * 13���������������������
- *
- * @param time
- * @param format
- * @return
- */
- public static String getLongToStr(long time, String format) {
- Date date = new Date(time);
- return dateToDateString(date, format);
- }
+ /**
+ * ������������n���������h������
+ *
+ * @param days
+ * @param hour
+ * @return
+ */
+ public static Long getPointDateHourTime(int days, int hour) {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.add(Calendar.DATE, days);
+ todayStart.set(Calendar.HOUR_OF_DAY, hour);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime();
+ }
- /**
- * ������������������������������������
- *
- * @param start
- * @param end
- * @return
- */
- public static int getIntervalSec(int start, int end) {
- return (end - start) * 60 * 60;
- }
+ /**
+ * ���������������������
+ *
+ * @param time
+ * @return
+ */
+ public static Integer hourTosec(String time) {
+ if ("null".equals(time) || StringUtils.isEmpty(time)) {
+ return null;
+ }
+ if (time.length() <= 5) {
+ time += ":00";
+ }
+ int index1 = time.indexOf(":");
+ int index2 = time.indexOf(":", index1 + 1);
+ int hh = Integer.parseInt(time.substring(0, index1));
+ int mi = Integer.parseInt(time.substring(index1 + 1, index2));
+ int ss = Integer.parseInt(time.substring(index2 + 1));
+ return hh * 60 * 60 + mi * 60 + ss;
+ }
- /**
- * ���������������������������������
- *
- * @param time
- * @return
- */
- public static String getMillsStr(long time) {
- String timeStr = String.valueOf(time);
- String suffix = timeStr.substring(0, timeStr.length() - 3);
- String prefix = timeStr.substring(timeStr.length() - 3, timeStr.length());
- return suffix + "." + prefix;
- }
+ /**
+ * ���������������������
+ *
+ * @param time
+ * @return
+ */
+ public static Integer minTosec(String time) {
+ if (time.length() <= 5) {
+ time += ":00";
+ }
+ int index1 = time.indexOf(":");
+ int index2 = time.indexOf(":", index1 + 1);
+ int mi = Integer.parseInt(time.substring(0, index1));
+ int ss = Integer.parseInt(time.substring(index1 + 1, index2));
+ return mi * 60 + ss;
+ }
- /**
- * ���������������������������������������������
- *
- * @param timeStr
- * @param formatStr
- * @return
- */
- public static String longToString(String timeStr, String formatStr) {
- long times = Long.parseLong(timeStr.replace(".", ""));
- Date date = new Date(times);
- return dateToDateString(date, formatStr);
- }
- /**
- * ������������������������
- *
- * @return
- */
- public static Long getTodayTime() {
- Calendar todayStart = Calendar.getInstance();
- todayStart.set(Calendar.HOUR_OF_DAY, 0);
- todayStart.set(Calendar.MINUTE, 0);
- todayStart.set(Calendar.SECOND, 0);
- todayStart.set(Calendar.MILLISECOND, 0);
- return todayStart.getTime().getTime();
- }
+ public static boolean isDate(String dateTimeStr, String formatStr) {
+ DateFormat df = getDateFormat(formatStr);
+ try {
+ df.parse(dateTimeStr);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
- public static Integer getTodayInt() {
- return (int) (getTodayTime() / 1000);
- }
+ /**
+ * ���������������������������������
+ *
+ * @param strDate ������������ yyyy-MM-dd HH:mm:ss
+ * @param strDateBegin ������������ 00:00:00
+ * @param strDateEnd ������������ 00:05:00
+ * @return
+ */
+ public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) {
+ // ���������������������������
+ int strDateH = Integer.parseInt(strDate.substring(11, 13));
+ int strDateM = Integer.parseInt(strDate.substring(14, 16));
+ int strDateS = Integer.parseInt(strDate.substring(17, 19));
+ // ���������������������������
+ int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
+ int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
+ int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
+ // ���������������������������
+ int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
+ int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
+ int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
+ if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
+ // ������������������������������������������������������������������
+ if (strDateH > strDateBeginH && strDateH < strDateEndH) {
+ return true;
+ // ������������������������������������������������������������������������������������
+ } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
+ return true;
+ // ������������������������������������������������������������������������������������������������������������������������
+ } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
+ && strDateS <= strDateEndS) {
+ return true;
+ }
+ // ���������������������������������������������������������������������������������������������������������������������������
+ else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
+ return true;
+ // ������������������������������������������������������������������������������������������������������������������������������������������������������������
+ } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
+ && strDateS <= strDateEndS) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
- /**
- * ������������������������
- *
- * @return
- */
- public static Long getEndTime() {
- Calendar todayEnd = Calendar.getInstance();
- todayEnd.set(Calendar.HOUR, 23);
- todayEnd.set(Calendar.MINUTE, 59);
- todayEnd.set(Calendar.SECOND, 59);
- todayEnd.set(Calendar.MILLISECOND, 999);
- return todayEnd.getTime().getTime();
- }
+ /**
+ * ���������������������������������
+ *
+ * @param date ������������ yyyy-MM-dd HH:mm:ss
+ * @param strDateBegin ������������ 00:00:00
+ * @param strDateEnd ������������ 00:05:00
+ * @return
+ */
+ public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String strDate = sdf.format(date);
+ // ���������������������������
+ int strDateH = Integer.parseInt(strDate.substring(11, 13));
+ int strDateM = Integer.parseInt(strDate.substring(14, 16));
+ int strDateS = Integer.parseInt(strDate.substring(17, 19));
+ // ���������������������������
+ int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
+ int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
+ int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
+ // ���������������������������
+ int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
+ int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
+ int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
+ if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
+ // ������������������������������������������������������������������
+ if (strDateH > strDateBeginH && strDateH < strDateEndH) {
+ return true;
+ // ������������������������������������������������������������������������������������
+ } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
+ return true;
+ // ������������������������������������������������������������������������������������������������������������������������
+ } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
+ && strDateS <= strDateEndS) {
+ return true;
+ }
+ // ���������������������������������������������������������������������������������������������������������������������������
+ else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
+ return true;
+ // ������������������������������������������������������������������������������������������������������������������������������������������������������������
+ } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
+ && strDateS <= strDateEndS) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
- public static Integer getTomorrowInt() {
- return (int) (getTomorrowTime() / 1000);
- }
+ public static boolean isInTime(int time, int begin, int end) {
+ if (time >= begin && time < end) {
+ return true;
+ }
+ return false;
+ }
- /**
- * ���������������������������
- *
- * @return
- */
- public static Long getTomorrowTime() {
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date());
- cal.set(Calendar.HOUR_OF_DAY, 0);
- cal.set(Calendar.MINUTE, 0);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- cal.add(Calendar.DAY_OF_MONTH, 1);
- return cal.getTime().getTime();
- }
+ public static int getMinutest(String begin, String format) {
+ String nowMinutes = getCurDate("HH:mm");
+ long time = compareDateStr("09:00", nowMinutes, "HH:mm");
+ return (int) time;
+ }
- /**
- * ���������������������������������
- *
- * @param hour
- * @return
- */
- public static Long getPointHourTime(int hour) {
- Calendar todayStart = Calendar.getInstance();
- todayStart.set(Calendar.HOUR_OF_DAY, hour);
- todayStart.set(Calendar.MINUTE, 0);
- todayStart.set(Calendar.SECOND, 0);
- todayStart.set(Calendar.MILLISECOND, 0);
- return todayStart.getTime().getTime();
- }
+ /**
+ * <p>
+ * Title: addDays
+ * </p>
+ * <p>
+ * Description: ������������
+ * </p>
+ *
+ * @param days
+ * @return
+ */
+ public static Date addDays(Date date, int days) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(Calendar.DATE, days);
+ return calendar.getTime();
+ }
- /**
- * ������������n���������h������
- *
- * @param days
- * @param hour
- * @return
- */
- public static Long getPointDateHourTime(int days, int hour) {
- Calendar todayStart = Calendar.getInstance();
- todayStart.add(Calendar.DATE, days);
- todayStart.set(Calendar.HOUR_OF_DAY, hour);
- todayStart.set(Calendar.MINUTE, 0);
- todayStart.set(Calendar.SECOND, 0);
- todayStart.set(Calendar.MILLISECOND, 0);
- return todayStart.getTime().getTime();
- }
+ /**
+ * <p>
+ * Title: addMonths
+ * </p>
+ * <p>
+ * Description: ������������
+ * </p>
+ *
+ * @param date
+ * @param months
+ * @return
+ */
+ public static Date addMonths(Date date, int months) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(Calendar.MONTH, months);
+ return calendar.getTime();
+ }
- /**
- * ���������������������
- *
- * @param time
- * @return
- */
- public static Integer hourTosec(String time) {
- if ("null".equals(time) || StringUtils.isEmpty(time)) {
- return null;
- }
- if (time.length() <= 5) {
- time += ":00";
- }
- int index1 = time.indexOf(":");
- int index2 = time.indexOf(":", index1 + 1);
- int hh = Integer.parseInt(time.substring(0, index1));
- int mi = Integer.parseInt(time.substring(index1 + 1, index2));
- int ss = Integer.parseInt(time.substring(index2 + 1));
- return hh * 60 * 60 + mi * 60 + ss;
- }
+ /**
+ * <p>
+ * Title: getDays
+ * </p>
+ * <p>
+ * Description: ���������������������������������������
+ * </p>
+ *
+ * @param minDate
+ * @param maxDate
+ * @return
+ */
+ public static int getDays(Date minDate, Date maxDate) {
+ int days = 0;
+ if (null == minDate || null == maxDate)
+ return days;
+ days = (int) ((maxDate.getTime() - minDate.getTime()) / (24 * 60 * 60 * 1000));
+ return days;
+ }
- /**
- * ���������������������
- *
- * @param time
- * @return
- */
- public static Integer minTosec(String time) {
- if (time.length() <= 5) {
- time += ":00";
- }
- int index1 = time.indexOf(":");
- int index2 = time.indexOf(":", index1 + 1);
- int mi = Integer.parseInt(time.substring(0, index1));
- int ss = Integer.parseInt(time.substring(index1 + 1, index2));
- return mi * 60 + ss;
- }
+ /**
+ * ������������ date
+ *
+ * @param longDate ���������
+ * @return
+ */
+ public static Date getConversionDateByLong(long longDate) {
+ //1529398742830
+ ZoneId zid = ZoneId.systemDefault();
+ LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(longDate), zid);
+ ZonedDateTime zdt = time.atZone(zid);
+ Date date = Date.from(zdt.toInstant());
+ return date;
+ }
+ /**
+ * yyyyMMdd ��� yyyy_MM_dd
+ *
+ * @param strData ���������
+ * @return
+ */
+ public static String getdatefor_yyyy_MM_dd(String strData) {
+ //1529398742830
+ //20180205
+ String yyyy_MM_dd = "";
+ if (null == strData || strData.length() == 0) {
+ return yyyy_MM_dd;
+ } else {
+ String yyyy = strData.substring(0, 4);
+ String mm = strData.substring(4, 6);
+ String dd = strData.substring(6, 8);
+ yyyy_MM_dd = yyyy + "-" + mm + "-" + dd;
+ }
+ return yyyy_MM_dd;
+ }
+ public static String getdatefor_HH_mm_ss(String strData) {
+ //1529398742830
+ //20180205
+ String HH_mm_ss = "";
+ if (null == strData || strData.length() == 0) {
+ return HH_mm_ss;
+ } else {
+ String HH = strData.substring(0, 2);
+ String mm = strData.substring(2, 4);
+ String ss = strData.substring(4, 6);
+ HH_mm_ss = HH + ":" + mm + ":" + ss;
+ }
+ return HH_mm_ss;
+ }
- public static boolean isDate(String dateTimeStr, String formatStr) {
- DateFormat df = getDateFormat(formatStr);
- try {
- df.parse(dateTimeStr);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
+ /**
+ * yyyyMMdd
+ *
+ * @return
+ */
+ public static String getdatefor_yyyyMMdd() {
+ Date newdate = new Date();
+ SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
+ String date = dft.format(newdate);
+ return date;
+ }
- /**
- * ���������������������������������
- *
- * @param strDate
- * ������������ yyyy-MM-dd HH:mm:ss
- * @param strDateBegin
- * ������������ 00:00:00
- * @param strDateEnd
- * ������������ 00:05:00
- * @return
- */
- public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) {
- // ���������������������������
- int strDateH = Integer.parseInt(strDate.substring(11, 13));
- int strDateM = Integer.parseInt(strDate.substring(14, 16));
- int strDateS = Integer.parseInt(strDate.substring(17, 19));
- // ���������������������������
- int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
- int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
- int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
- // ���������������������������
- int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
- int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
- int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
- if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
- // ������������������������������������������������������������������
- if (strDateH > strDateBeginH && strDateH < strDateEndH) {
- return true;
- // ������������������������������������������������������������������������������������
- } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
- return true;
- // ������������������������������������������������������������������������������������������������������������������������
- } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
- && strDateS <= strDateEndS) {
- return true;
- }
- // ���������������������������������������������������������������������������������������������������������������������������
- else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
- return true;
- // ������������������������������������������������������������������������������������������������������������������������������������������������������������
- } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
- && strDateS <= strDateEndS) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
+ /**
+ * yyyyMMdd
+ *
+ * @return
+ */
+ public static String getdatefor_yyyy_MM_dd() {
+ Date newdate = new Date();
+ SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
+ String date = dft.format(newdate);
+ return date;
+ }
- /**
- * ���������������������������������
- *
- * @param date
- * ������������ yyyy-MM-dd HH:mm:ss
- * @param strDateBegin
- * ������������ 00:00:00
- * @param strDateEnd
- * ������������ 00:05:00
- * @return
- */
- public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String strDate = sdf.format(date);
- // ���������������������������
- int strDateH = Integer.parseInt(strDate.substring(11, 13));
- int strDateM = Integer.parseInt(strDate.substring(14, 16));
- int strDateS = Integer.parseInt(strDate.substring(17, 19));
- // ���������������������������
- int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
- int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
- int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
- // ���������������������������
- int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
- int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
- int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
- if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
- // ������������������������������������������������������������������
- if (strDateH > strDateBeginH && strDateH < strDateEndH) {
- return true;
- // ������������������������������������������������������������������������������������
- } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
- return true;
- // ������������������������������������������������������������������������������������������������������������������������
- } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
- && strDateS <= strDateEndS) {
- return true;
- }
- // ���������������������������������������������������������������������������������������������������������������������������
- else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
- return true;
- // ������������������������������������������������������������������������������������������������������������������������������������������������������������
- } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
- && strDateS <= strDateEndS) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
+ //���������������������������������
+ public static Date dataToTimeStampTime(Date time, String dateFormat) {
+ String dateString = dateToDateString(time, dateFormat);
+ try {
+ return getDateFormat(dateFormat).parse(dateString);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
- public static boolean isInTime(int time, int begin, int end) {
- if (time >= begin && time < end) {
- return true;
- }
- return false;
- }
+ //���������������
+ public static Date getLastWeekMonday() {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(getDate(getMondayOfThisWeek(), yyyy_MM_dd_EN));
+ cal.add(Calendar.DATE, -7);
+ return cal.getTime();
+ }
- public static int getMinutest(String begin, String format) {
- String nowMinutes = getCurDate("HH:mm");
- long time = compareDateStr("09:00", nowMinutes, "HH:mm");
- return (int) time;
- }
+ //���������������������
+ public static Date getFirstDayOfLastMonth() {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.MONTH, -1);
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ return getDate(dateToDateString(calendar.getTime(), yyyy_MM_dd_EN));
+ }
- /**
- * <p>
- * Title: addDays
- * </p>
- * <p>
- * Description: ������������
- * </p>
- *
- * @param days
- * @return
- */
- public static Date addDays(Date date, int days) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.add(Calendar.DATE, days);
- return calendar.getTime();
- }
- /**
- * <p>
- * Title: addMonths
- * </p>
- * <p>
- * Description: ������������
- * </p>
- *
- * @param date
- * @param months
- * @return
- */
- public static Date addMonths(Date date, int months) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.add(Calendar.MONTH, months);
- return calendar.getTime();
- }
+ /*���������������������*/
+ public static String getDateAddYear(String date, int year) {
+ DateFormat df = getDateFormat(yyyy);
+ try {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(df.parse(date));
+ cal.add(Calendar.YEAR, year);
+ date = df.format(cal.getTime());
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ return date;
+ }
- /**
- * <p>
- * Title: getDays
- * </p>
- * <p>
- * Description: ���������������������������������������
- * </p>
- *
- * @param minDate
- * @param maxDate
- * @return
- */
- public static int getDays(Date minDate, Date maxDate) {
- int days = 0;
- if (null == minDate || null == maxDate)
- return days;
- days = (int) ((maxDate.getTime() - minDate.getTime()) / (24 * 60 * 60 * 1000));
- return days;
- }
+ /*
+ * ������������������������������������
+ * ������time=2021-08-04 ���������������������������������������2021-08-04 00���2021-08-04 01���������
+ * time=2021-08 ���������������������������������
+ * */
+ public static List<String> getTimeLag(String time) {
+ List<String> result = new ArrayList<>();
+ int length = time.length();
+ Calendar cal = Calendar.getInstance();
+ String end;
+ String dateFormat;
+ String df;
+ int i;
+ if (length == 10) {//���
+ end = getDateAddDay(time, 1);
+ dateFormat = yyyy_MM_dd_HH_EN;
+ df = yyyy_MM_dd_EN;
+ i = Calendar.HOUR_OF_DAY;
+ } else if (length == 7) {//���
+ end = getDateAddMonth(time, 1);
+ dateFormat = yyyy_MM_dd_EN;
+ df = yyyy_MM_EN;
+ i = Calendar.DAY_OF_MONTH;
+ } else {//���
+ end = getDateAddYear(time, 1);
+ dateFormat = yyyy_MM_EN;
+ df = yyyy;
+ i = Calendar.MONTH;
+ }
+ cal.setTime(getDate(time, df));
+ for (long d = cal.getTimeInMillis(); d < getDate(end, df).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) {
+ String format = dateToDateString(new Date(d),dateFormat);
+ result.add(format);
+ }
+ return result;
+ }
- /**
- * ������������ date
- *
- * @param longDate ���������
- * @return
- */
- public static Date getConversionDateByLong(long longDate) {
- //1529398742830
- ZoneId zid = ZoneId.systemDefault();
- LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(longDate), zid);
- ZonedDateTime zdt = time.atZone(zid);
- Date date = Date.from(zdt.toInstant());
- return date;
- }
-
- /**
- * yyyyMMdd ��� yyyy_MM_dd
- *
- * @param strData ���������
- * @return
- */
- public static String getdatefor_yyyy_MM_dd(String strData) {
- //1529398742830
- //20180205
- String yyyy_MM_dd="";
- if (null == strData || strData.length()==0) {
- return yyyy_MM_dd;
- }else {
- String yyyy = strData.substring(0, 4);
- String mm = strData.substring(4, 6);
- String dd = strData.substring(6, 8);
- yyyy_MM_dd = yyyy+"-"+mm +"-"+dd;
- }
- return yyyy_MM_dd;
- }
-
- public static String getdatefor_HH_mm_ss(String strData) {
- //1529398742830
- //20180205
- String HH_mm_ss="";
- if (null == strData || strData.length()==0) {
- return HH_mm_ss;
- }else {
- String HH = strData.substring(0, 2);
- String mm = strData.substring(2, 4);
- String ss = strData.substring(4, 6);
- HH_mm_ss = HH+":"+mm +":"+ss;
- }
- return HH_mm_ss;
- }
-
- /**
- * yyyyMMdd
- *
- * @return
- */
- public static String getdatefor_yyyyMMdd() {
- Date newdate = new Date();
- SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
- String date = dft.format(newdate);
- return date;
- }
-
- /**
- * yyyyMMdd
- *
- * @return
- */
- public static String getdatefor_yyyy_MM_dd() {
- Date newdate = new Date();
- SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
- String date = dft.format(newdate);
- return date;
- }
-
-
-
- public static void main(String[] args) throws InterruptedException {
- Date date1 = new Date();
- Thread.sleep(1000);
- Date date2 = new Date();
- System.out.println(DateUtils.compareDateStr(date1,date2));
- }
+ //������date���������������������������0���5���������������������2021-08-09 15:32:00->2021-08-09 15:30:00���2021-08-09 15:39:00->2021-08-09 15:35:00
+ public static Date getFiveMinuteDate(Date date) {
+ String dateString = dateToDateString(date, yyyy_MM_dd_HH_mm_EN);
+ String minute = dateString.substring(15, 16);
+ int i = Integer.parseInt(minute);
+ if (i > 0 && i < 5) {
+ i = 0;
+ } else if (i > 5 && i <= 9) {
+ i = 5;
+ }
+ StringBuilder stringBuffer = new StringBuilder(dateString);
+ stringBuffer.replace(15, 16, String.valueOf(i));
+ return getDate(stringBuffer.toString(), yyyy_MM_dd_HH_mm_EN);
+ }
}
--
Gitblit v1.8.0