package 。。。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
|-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.|
| ______ |
| .-" "-. |
| / \ |
| _ | | _ |
| ( \ |, .-. .-. ,| / ) |
| > "=._ | )(__/ \__)( | _.=" < |
| (_/"=._"=._ |/ /\ \| _.="_.="\_) |
| "=._"(_ ^^ _)"_.=" |
| "=\__|IIIIII|__/=" |
| _.="| \IIIIII/ |"=._ |
| _ _.="_.="\ /"=._"=._ _ |
| ( \_.="_.=" `--------` "=._"=._/ ) |
| > _.=" "=._ < |
| (_/ NO BUG ! \_) |
| |
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='
* @description: DateUtils
* @author chenjiandong
* @date 2019/6/21 14:20
*/
public class DateUtils {
/**
* <獲取當前時間 格式yyyy-MM-dd hh:mm:ss> <功能詳細描述>
*
* @return String
* @see [類、類#方法、類#成員]
*/
public static String getNowTime() {
Date date = new Date();
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return df2.format(date);
}
/**
* <獲取當前時間 格式yyyy-MM-dd> <功能詳細描述>
*
* @return String
* @see [類、類#方法、類#成員]
*/
public static String getNowDate() {
Date date = new Date();
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
return df2.format(date);
}
/**
* <獲取當前時間 格式yyyyMMddhhmmss> <功能詳細描述>
*
* @return String
* @see [類、類#方法、類#成員]
*/
public static String getRightTime() {
Date date = new Date();
SimpleDateFormat fm = new SimpleDateFormat("yyyyMMddHHmmss");
return fm.format(date);
}
/**
* <獲取當前時間 格式yyyyMMdd> <功能詳細描述>
*
* @return String
* @see [類、類#方法、類#成員]
*/
public static String getRightDate() {
Date date = new Date();
SimpleDateFormat fm = new SimpleDateFormat("yyyyMMdd");
return fm.format(date);
}
/**
* 獲取yyyy-MM-dd HH:mm:ss時間,去掉末尾的.0
*
* @param strDate 2019-06-04 12:12:12.0
* @return String
*/
public static String removeTime0(String strDate) {
return strDate.replace(".0", "");
}
/**
* <查看兩個時間點間隔多少天 當前時間和傳進來的時間比較>
*
* @return String
* @see [類、類#方法、類#成員]
*/
public static Integer getTwoDateGap(String destDate) throws Exception{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String nowDate = getNowDate();
Date now = sdf.parse(nowDate);
Date end = sdf.parse(destDate);
long days=(end.getTime()-now.getTime())/(1000*3600*24);
return Integer.valueOf(String.valueOf(days));
}
/**
* 計算兩個日期之間的時間差是否小於120秒
*
* @param time1
* @return s
* @throws Exception
*/
public static Boolean getCountTimes(Long time1) throws Exception {
long b = System.currentTimeMillis();
int c = (int) ((b - time1) / 1000);
try {
if (c < 120) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}