mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-10 15:44:58 +08:00
代码优化
This commit is contained in:
@@ -8,34 +8,35 @@ import java.util.*;
|
||||
|
||||
/**
|
||||
* 日期转换运算工具
|
||||
* @author egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2018-11-21 16:43:20
|
||||
* </pre>
|
||||
*
|
||||
* @author egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2018-11-21 16:43:20
|
||||
* </pre>
|
||||
*/
|
||||
public final class DateUtils {
|
||||
|
||||
static final class DateFormatHolder {
|
||||
private static final ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>> THREADLOCAL_FORMATS = new ThreadLocal();
|
||||
private static final ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>> THREADLOCAL_FORMATS = new ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>>();
|
||||
|
||||
DateFormatHolder() {
|
||||
}
|
||||
|
||||
public static SimpleDateFormat formatFor(String pattern) {
|
||||
SoftReference ref = (SoftReference)THREADLOCAL_FORMATS.get();
|
||||
Object formats = ref == null?null:(Map)ref.get();
|
||||
if(formats == null) {
|
||||
formats = new HashMap();
|
||||
SoftReference<Map<String, SimpleDateFormat>> ref = THREADLOCAL_FORMATS.get();
|
||||
Map<String, SimpleDateFormat> formats = ref == null ? null : ref.get();
|
||||
if (formats == null) {
|
||||
formats = new HashMap<String, SimpleDateFormat>();
|
||||
THREADLOCAL_FORMATS.set(new SoftReference(formats));
|
||||
}
|
||||
|
||||
SimpleDateFormat format = (SimpleDateFormat)((Map)formats).get(pattern);
|
||||
SimpleDateFormat format = formats.get(pattern);
|
||||
|
||||
if(format == null) {
|
||||
if (format == null) {
|
||||
format = new SimpleDateFormat(pattern);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
||||
((Map)formats).put(pattern, format);
|
||||
((Map) formats).put(pattern, format);
|
||||
}
|
||||
|
||||
return format;
|
||||
@@ -46,8 +47,8 @@ public final class DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
public static final String YYYYMMDD = "yyyyMMdd";
|
||||
public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
public static final String MMDD = "MMdd";
|
||||
@@ -56,41 +57,46 @@ public final class DateUtils {
|
||||
public static String formatDate(Date date, String pattern) {
|
||||
Args.notNull(date, "Date");
|
||||
Args.notNull(pattern, "Pattern");
|
||||
SimpleDateFormat formatFor = DateFormatHolder.formatFor(pattern);
|
||||
SimpleDateFormat formatFor = DateFormatHolder.formatFor(pattern);
|
||||
return formatFor.format(date);
|
||||
}
|
||||
public static final String format(Date date){
|
||||
|
||||
public static final String format(Date date) {
|
||||
return formatDate(date, YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
|
||||
public static final String formatDay(Date date){
|
||||
return formatDate(date, YYYY_MM_DD);
|
||||
public static final String formatDay(Date date) {
|
||||
return formatDate(date, YYYY_MM_DD);
|
||||
}
|
||||
|
||||
/**
|
||||
* 剩余分钟数
|
||||
*
|
||||
* @param date 结束点日期
|
||||
* @return 分钟数
|
||||
*/
|
||||
public static final long minutesRemaining(Date date){
|
||||
return (date.getTime() - System.currentTimeMillis()) / 1000 / 60 ;
|
||||
public static final long minutesRemaining(Date date) {
|
||||
return (date.getTime() - System.currentTimeMillis()) / 1000 / 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剩余小时
|
||||
*
|
||||
* @param date 结束点日期
|
||||
* @return 小时数
|
||||
*/
|
||||
public static final long remainingHours(Date date){
|
||||
return minutesRemaining(date) / 60 ;
|
||||
public static final long remainingHours(Date date) {
|
||||
return minutesRemaining(date) / 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剩余天数
|
||||
*
|
||||
* @param date 结束点日期
|
||||
* @return 天数
|
||||
*/
|
||||
public static final long remainingDays(Date date){
|
||||
return remainingHours(date) / 24 ;
|
||||
public static final long remainingDays(Date date) {
|
||||
return remainingHours(date) / 24;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ public class CertDescriptor {
|
||||
*/
|
||||
private X509Certificate rootKeyCert = null;
|
||||
|
||||
public CertDescriptor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过证书路径初始化为公钥证书
|
||||
|
||||
Reference in New Issue
Block a user