天天看點

Java實作自定義序列

一、關于自定義序列計算

1、實作需求

每天的訂單序号

yyyyMMdd0001

1)     入口參數

a)      日期

b)     目前序号

2)     出口

傳回一個字元串序号

2、         采用DecimalFormat,SimpleDateFormat

3、         示例如下

public class TestAutoSelfPK {

     static String getPK(Date dt,int id){

            id++;

            SimpleDateFormat df=new SimpleDateFormat("yyyyMMdd");

            String dtString=df.format(dt);

//        Log.getLog().info("dtString="+dtString);

            DecimalFormat dcf=new DecimalFormat("'"+dtString+"-'000");

            String value=dcf.format(id);

            return value;

     }

     public static void main(String[] args) {

//        Date dt=new Date(117,4,16)

繼續閱讀