1 private final static String FORMAT_CODE = "0000"; 2 private final static String PRE_CODE = "BM"; 3 @Test 4 public void FormatCode() { 5 int count = 1; // 流水号 6 DecimalFormat dft = new DecimalFormat(FORMAT_CODE); 7 String code = dft.format(count); // 格式化为四位流水号 code: 0001 8 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 9 String date = sdf.format(new Date()); // 格式化日期 date: 20200724 10 String codeEnd = PRE_CODE + date + code; 11 System.out.println(codeEnd); 12 }
输出结果为 : BM202007240001