// 設置初始化值爲5 private static AtomicInteger count = new AtomicInteger(5);
// 生成發票流水號的8位年月日與4位序列號 private static String issueInvoiceSerival(){ Timestamp curDate = new Timestamp(System.currentTimeMillis()); String[] str = curDate.toString().split(" ")[0].split("-"); String dateTemp = str[0] + str[1] + str [2]; return dateTemp + String.format("%04d", count.incrementAndGet()); } // Java之四位序列號生成方式 String.format("%04d", count.incrementAndGet());