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


    /**
     * 金额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);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    /**
         * @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;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
      /**
         * @param str 字符串
         * @return true 全为数字 false 非全为数字
         * @description 判断字符串是否全为数字
         */
        public static boolean isNumeric(String str){
            Pattern pattern = Pattern.compile("[0-9]*");
            return pattern.matcher(str).matches();
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
     /**
        * @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();
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    /**
         * @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})?");
            
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    /**
         * @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);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
  • 相关阅读:
    opencv学习之基础
    抖音矩阵系统,抖音矩阵系统,抖音矩阵系统,抖音矩阵系统,抖音矩阵系统,抖音矩阵系统,抖音矩阵系统,抖音矩阵系统。。
    Redis五大基本数据类型
    朋友问我,你都30岁了学编程来得及吗
    Dubbo+Zookeeper搭建
    【华为机试真题 JAVA】免单统计-100
    DNS用的是TCP协议还是UDP协议
    线段树
    记录crack某IDE插件过程
    一键解决Win10 LTSC 2021官方镜像存在的问题
  • 原文地址:https://blog.csdn.net/weixin_56287335/article/details/126763081