Java实现自定义序列

一、关于自定义序列计算

1、实现需求

每天的订单序号

yyyyMMdd0001

1)     入口参数

a)      日期

b)     当前序号

2)     出口

返回一个字符串序号

2、         采用DecimalFormat,SimpleDateFormat

3、         示例如下

扫描二维码关注公众号,回复: 1447267 查看本文章

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);

            Date dt=new Date(); //当前日期

            int id=145;

            String myid=getPK(dt, id);

            Log.getLog().info("myid="+myid);

     }

}

输出如下

iss.autopk.TestAutoSelfPK.main(TestAutoSelfPK.java:33)11-27 10:51:27>

myid=20171127-146

猜你喜欢

转载自blog.csdn.net/qq_34520606/article/details/78660103