| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.regex.Matcher; |
| | |
| | | * 格式化当前系统日期 2 |
| | | */ |
| | | public static final SimpleDateFormat YMDHMS_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | public static final double D1024 = 1024.0; |
| | | |
| | | /** |
| | | * 判断字符串,是否为数字 |
| | |
| | | public static String capitalize(String str) { |
| | | return String.valueOf(str.charAt(0)).toUpperCase() + str.substring(1); |
| | | } |
| | | |
| | | /** |
| | | * 校验密码是/否合法 |
| | | * |
| | | * @param pwd 密码 |
| | | * @return 是/否合法 |
| | | */ |
| | | public static boolean checkPwdValid(String pwd) { |
| | | return Pattern.matches(StaticData.PWD_REG, pwd); |
| | | } |
| | | |
| | | /** |
| | | * 字节单位换算 |
| | | * |
| | | * @param byteNumber |
| | | * @return |
| | | */ |
| | | public static String formatByte(long byteNumber) { |
| | | double kbNumber = byteNumber / D1024; |
| | | if (kbNumber < D1024) { |
| | | return new DecimalFormat("#.##KB").format(kbNumber); |
| | | } |
| | | double mbNumber = kbNumber / D1024; |
| | | if (mbNumber < D1024) { |
| | | return new DecimalFormat("#.##MB").format(mbNumber); |
| | | } |
| | | double gbNumber = mbNumber / D1024; |
| | | if (gbNumber < D1024) { |
| | | return new DecimalFormat("#.##GB").format(gbNumber); |
| | | } |
| | | double tbNumber = gbNumber / D1024; |
| | | |
| | | return new DecimalFormat("#.##TB").format(tbNumber); |
| | | } |
| | | } |