[工具方法]java常用的工具方法整理 字符串补充为固定长度 /** * title: The append character 0 becomes an integer multiple of 16 */ private static String appendZeroToIntegralMultipleOf16(String str){ int length = str.length(); int addPoint = 16 - length % 16; if (addPoint == 16) { return str; } char[] chars =new char[addPoint]; Arrays.fill(chars, '0'); // return new StringBuilder(str).append(chars).toString(); return str + new String(chars); } 显示数字格式化 public static void main(String[] args) { System.out.println(new DecimalFormat("ID_,####").format(1234567890123456789L)); //ID_123,4567,8901,2345,6789 DecimalFormat d1 = new DecimalFormat("0.00"); } 当天的22:00:00:000 /** * title: 当天的22:00:00:000 * 2019/7/9 */ private static Date getThatDay220000(Date date){ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); // 时 calendar.set(Calendar.HOUR_OF_DAY, 22); // 分 calendar.set(Calendar.MINUTE, 0); // 秒 calendar.set(Calendar.SECOND, 0); // 毫秒 calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }