---
# System prepended metadata

title: 民國年月取號機
tags: [Java]

---

```java=
    public String getNewSeq(String lastFormId) {
        LocalDate localDate = LocalDate.now();
        String year = String.valueOf(localDate.getYear() - 1911);
        String mon = String.valueOf(localDate.getMonthValue()).length() > 1 ? String.valueOf(localDate.getMonthValue()) : "0" + localDate.getMonthValue();
        if (lastFormId != null) {
            String[] lastFormIdFragment = lastFormId.split("-");
            String lastSeq = lastFormIdFragment[2];
            String lastSeqYYMM = lastFormIdFragment[1];
            if (lastSeqYYMM.equals(year + mon)) {
                int num = Integer.parseInt(lastSeq) + 1;
                String newSeq = String.format("%04d", num);
                return lastSeqYYMM +"-"+ newSeq;
            }
        }
        return  year + mon+ "-0001";
    }
```