天天看点

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)

继续阅读