记录一下自己涉及到的时间及金额方法的处理

/**
 * 金额format工具
 * @param xyje
 * @return 千分位协议金额
 */
public static String StringFmtMicrometer(String xyje){
    DecimalFormat df = null;
    if(xyje.indexOf(".") > 0)
    {
        if(xyje.length() - xyje.indexOf(".")-1 == 0)
        {
            df = new DecimalFormat("###,##0.");
        }else if(xyje.length() - xyje.indexOf(".")-1 == 1)
        {
            df = new DecimalFormat("###,##0.0");
        }else
        {
            df = new DecimalFormat("###,##0.00");
        }
    }else
    {
        df = new DecimalFormat("###,##0");
    }
    double number = 0.0;
    try {
        number = Double.parseDouble(xyje);
    } catch (Exception e) {
        number = 0.0;
    }
    return df.format(number);
}
/**
     * @param str 字符串
     * @return num 字符串中抽取出来的数字
     * @description 从字符串中抽取数字
     */
    public String strExtractLong(String str){
        String num="";
        if(StringUtils.isNotEmpty(str)){
            String regEx = "[^0-9]";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(str);
            num= m.replaceAll("").trim();
        }
        return num;
    }
  /**
     * @param str 字符串
     * @return true 全为数字 false 非全为数字
     * @description 判断字符串是否全为数字
     */
    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }
 /**
    * @param date 时间
    * @param year 年数
    * @return 增加之后的时间
    * @description 在date时间上增加多少年
    */
    public static Date dateAddYear(Date date ,Integer year){
        Calendar cal = Calendar.getInstance();
        //设置起始时间
        cal.setTime(date);
        //增加多少年
        cal.add(Calendar.YEAR, year);
        return cal.getTime();
    }
/**
     * @param str
     * @return true:是,false不是
     * @description 判断是否是整数或者是小数
     */
    public static boolean validateNumber(String str) {
        if(StringUtils.isBlank(str)) {
            return false;
        }
        // 说明一下的是该正则只能识别5位小数;如果不限制小数位数的话,写成[+-]?[0-9]+(\\.[0-9]+)?就可以了
        return str.matches("[+-]?[0-9]+(\\.[0-9]{1,6})?");
        
    }
/**
     * @param dateTime 时间
     * @return 字符串格式化时间
     * @description 将date时间转化成 yyyy-MM-dd HH:mm:ss 格式的字符串时间
     */
    public static String dateConversionStr(Date dateTime) {
        if (ObjectUtils.isEmpty(dateTime)){
            return "";
        }
        //定义转化为字符串的日期格式 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //将时间转化为字符串格式日期
        return sdf.format(dateTime);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

于歌852

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值