简单的唯一数字订单号生成


package test;
import java.util.Date;
import java.util.Random;

public class NOUtil {
    private static Date date = new Date();
    private static StringBuilder buf = new StringBuilder();
    private static int seq = 1;
    private static final int ROTATION = 9;

    public static synchronized long next() {
        if (seq > ROTATION)
            seq = 1;
        buf.delete(0, buf.length());
        date.setTime(System.currentTimeMillis());
        String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$01d%3$03d",
                date, seq++,new Random().nextInt(999));
        return Long.parseLong(str);
    }
}

声明:唐踢踢|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 简单的唯一数字订单号生成


生活不只是眼前的苟且,还有诗和远方。