From ad4aa3dea3554b168824e426e66bd9849e3193d4 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 20 六月 2019 17:08:43 +0800
Subject: [PATCH] 文档重新整理加入 开发环境搭建和生产环境搭建步骤
---
java110-common/src/main/java/com/java110/common/util/DateUtil.java | 153 +++++++++++++++++++++++++++++++-------------------
1 files changed, 94 insertions(+), 59 deletions(-)
diff --git a/java110-common/src/main/java/com/java110/common/util/DateUtil.java b/java110-common/src/main/java/com/java110/common/util/DateUtil.java
index 9f09542..8ee9cec 100644
--- a/java110-common/src/main/java/com/java110/common/util/DateUtil.java
+++ b/java110-common/src/main/java/com/java110/common/util/DateUtil.java
@@ -1,5 +1,6 @@
package com.java110.common.util;
+import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -29,8 +30,7 @@
public static final String DATE_FORMATE_STRING_J = "yyyyMMddHHmmss.SSS";
public static final String DATE_FORMATE_STRING_K = "yyyyMMddHHmmssSSS";
- static
- {
+ static {
formats.put("yyyyMMddHHmmss", new SimpleDateFormat("yyyyMMddHHmmss"));
formats.put("yyyy-MM-dd HH:mm:ss", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
formats.put("yyyy-MM-dd", new SimpleDateFormat("yyyy-MM-dd"));
@@ -48,18 +48,62 @@
/**
* 杩斿洖 yyyyMMddhhmmss 鏍煎紡鐨勬棩鏈熶覆
+ *
* @return
*/
- public static String getyyyyMMddhhmmssDateString(){
+ public static String getyyyyMMddhhmmssDateString() {
return dateFormat.format(new Date());
}
+ /**
+ * 鑾峰彇褰撳墠鏃堕棿
+ *
+ * @return
+ */
+ public static Date getCurrentDate() {
+ Calendar calendar = Calendar.getInstance();
+ return calendar.getTime();
+ }
+ /**
+ * 鑾峰彇褰撳墠鏈�
+ *
+ * @return
+ */
+ public static int getCurrentMonth() {
+ Calendar calendar = Calendar.getInstance();
+ return calendar.get(Calendar.MONTH) + 1;
+ }
+ public static Date getLastDate() throws ParseException {
+ return getDateFromString("3000-01-01", DATE_FORMATE_STRING_B);
+ }
- public static String getFormatTimeString(Date date, String pattern)
- {
+ /**
+ * 杞琓imeStamp
+ *
+ * @param date
+ * @return
+ */
+ public static Timestamp getTimestamp(Date date) {
+ Timestamp timestamp = new Timestamp(date.getTime());
+ return timestamp;
+ }
+
+ /**
+ * 鑾峰彇鏈潵鏃堕棿
+ *
+ * @param second 绉�
+ * @return
+ */
+ public static Date getFutureDate(int second) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, second);
+ return calendar.getTime();
+ }
+
+ public static String getFormatTimeString(Date date, String pattern) {
SimpleDateFormat sDateFormat = getDateFormat(pattern);
synchronized (sDateFormat) {
@@ -67,14 +111,12 @@
}
}
- public static String getDefaultFormateTimeString(Date date)
- {
+ public static String getDefaultFormateTimeString(Date date) {
return getFormatTimeString(date, "yyyyMMddHHmmss");
}
- public static SimpleDateFormat getDateFormat(String pattern)
- {
- SimpleDateFormat sDateFormat = (SimpleDateFormat)formats.get(pattern);
+ public static SimpleDateFormat getDateFormat(String pattern) {
+ SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
if (sDateFormat == null) {
sDateFormat = new SimpleDateFormat(pattern);
formats.put(pattern, sDateFormat);
@@ -83,8 +125,7 @@
}
public static Date getDateFromString(String date, String pattern)
- throws ParseException
- {
+ throws ParseException {
SimpleDateFormat sDateFormat = getDateFormat(pattern);
synchronized (sDateFormat) {
@@ -93,72 +134,76 @@
}
public static Date getDefaultDateFromString(String date)
- throws ParseException
- {
+ throws ParseException {
return getDateFromString(date, "yyyyMMddHHmmss");
}
- public static String getNowDefault()
- {
+ public static String getNowDefault() {
return getNow("yyyyMMddHHmmss");
}
- public static String getNow(String pattern)
- {
+ public static String getNow(String pattern) {
return getFormatTimeString(new Date(), pattern);
}
- public static String getNowII()
- {
+ public static String getNowII() {
return getFormatTimeString(new Date(), "yyyyMMdd");
}
public static long dateString2Long(String str, String pattern)
- throws ParseException
- {
+ throws ParseException {
return getDateFromString(str, pattern).getTime();
}
- public static String longToDateStringDefault(long time)
- {
+ /**
+ * 鏍¢獙瀛楃涓叉槸鍚﹀彲浠ユ牸寮忓寲涓烘椂闂�
+ *
+ * @param str
+ * @param pattern
+ * @return
+ */
+ public static boolean judgeDate(String str, String pattern) {
+ try {
+ dateString2Long(str, pattern);
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+
+ public static String longToDateStringDefault(long time) {
return getFormatTimeString(new Date(time), "yyyyMMddHHmmss");
}
- public static String longToDateString(long time, String pattern)
- {
+ public static String longToDateString(long time, String pattern) {
return getFormatTimeString(new Date(time), pattern);
}
- public static long date2Long(Date date)
- {
+ public static long date2Long(Date date) {
return date.getTime();
}
- public static Date longToDate(long time)
- {
+ public static Date longToDate(long time) {
return new Date(time);
}
public static Date getDateFromStringAdaptTwoPattern(String date)
- throws ParseException
- {
- try
- {
- return getDateFromString(date, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) {
+ throws ParseException {
+ try {
+ return getDateFromString(date, "yyyy-MM-dd HH:mm:ss");
+ } catch (ParseException e) {
}
return getDateFromString(date, "yyyy-MM-dd");
}
public static String changeNumDateToDate(String numdate, String inFormat, String outFormat)
- throws ParseException
- {
+ throws ParseException {
Date date = getDateFromString(numdate, inFormat);
return getFormatTimeString(date, outFormat);
}
public static String getNextMonthFistDay(String nowdate, String inFormat, String outFormat)
- throws ParseException
- {
+ throws ParseException {
Date date = getDateFromString(nowdate, inFormat);
Calendar cl = Calendar.getInstance();
@@ -170,12 +215,10 @@
return getFormatTimeString(date, outFormat);
}
- public static boolean isLeapYear(int year)
- {
+ public static boolean isLeapYear(int year) {
if (year % 400 == 0)
return true;
- if (year % 4 == 0)
- {
+ if (year % 4 == 0) {
return (year % 100 != 0);
}
@@ -183,16 +226,14 @@
}
public static String getLastDay(String nowdate, String inFormat, String outFormat)
- throws ParseException
- {
+ throws ParseException {
String returndate = "";
Date date = getDateFromString(nowdate, inFormat);
Calendar cl = Calendar.getInstance();
cl.setTime(date);
- switch (cl.get(2))
- {
+ switch (cl.get(2)) {
case 0:
cl.set(5, 31);
break;
@@ -243,13 +284,11 @@
return returndate;
}
- public static String getMonthLastDay(String fmt)
- {
+ public static String getMonthLastDay(String fmt) {
String returndate = "";
Date date = null;
Calendar cl = Calendar.getInstance();
- switch (cl.get(2))
- {
+ switch (cl.get(2)) {
case 0:
cl.set(5, 31);
break;
@@ -300,8 +339,7 @@
return returndate;
}
- public static String getNextMonthFirstDay(String fmt)
- {
+ public static String getNextMonthFirstDay(String fmt) {
String returndate = "";
Date date = null;
@@ -317,8 +355,7 @@
}
public static boolean compareDate(String fistDate, String secondDate, String format)
- throws ParseException
- {
+ throws ParseException {
boolean flag = false;
Date fist = null;
@@ -334,10 +371,8 @@
return flag;
}
- public static boolean isRightDate(String value, String varValue)
- {
- try
- {
+ public static boolean isRightDate(String value, String varValue) {
+ try {
SimpleDateFormat format = new SimpleDateFormat(varValue);
format.setLenient(false);
format.parse(value);
--
Gitblit v1.8.0