代码优化

This commit is contained in:
egan
2018-11-21 22:44:06 +08:00
parent d341f3ce37
commit 1f22072891
11 changed files with 227 additions and 179 deletions

View File

@@ -15,11 +15,18 @@ import java.util.TimeZone;
*/
public final class DateUtils {
public static final DateFormat YYYY_MM_DD_HH_MM_SS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final DateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final DateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
public static final DateFormat YYYYMMDD = new SimpleDateFormat("yyyyMMdd");
public static final DateFormat YYYYMMDDHHMMSS = new SimpleDateFormat("yyyyMMddHHmmss");
public static final DateFormat MMDD = new SimpleDateFormat("MMdd");
static {
YYYY_MM_DD_HH_MM_SS.setTimeZone(TimeZone.getTimeZone("GMT+8"));
YYYY_MM_DD.setTimeZone(TimeZone.getTimeZone("GMT+8"));
TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
YYYY_MM_DD_HH_MM_SS.setTimeZone(timeZone);
YYYY_MM_DD.setTimeZone(timeZone);
YYYYMMDD.setTimeZone(timeZone);
YYYYMMDDHHMMSS.setTimeZone(timeZone);
MMDD.setTimeZone(timeZone);
}
public static final String format(Date date){

View File

@@ -1,5 +1,6 @@
package com.egzosn.pay.common.util;
import java.math.BigDecimal;
import java.math.BigInteger;
public class Util{
@@ -610,4 +611,23 @@ public class Util{
return bt;
}
/**
* 元转分
* @param amount 元的金额
* @return 分的金额
*/
public static final int conversionCentAmount(BigDecimal amount){
return amount.multiply(new BigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
/**
* 元,两位小数
* @param amount 元的金额
* @return 元的金额 两位小数
*/
public static final BigDecimal conversionAmount(BigDecimal amount){
return amount.setScale(2, BigDecimal.ROUND_HALF_UP);
}
}