博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java生成流水号 - 1
阅读量:4130 次
发布时间:2019-05-25

本文共 1412 字,大约阅读时间需要 4 分钟。

流水号格式为yyyyMMddXXXX,规定每天只能到9999,代码如下:

import java.text.DecimalFormat;import java.text.SimpleDateFormat;import java.util.Date; public class PrimaryGenerater {     private static final String SERIAL_NUMBER = "XXXX"; // 流水号格式    private static PrimaryGenerater primaryGenerater = null;     private PrimaryGenerater() {    }     /**     * 取得PrimaryGenerater的单例实现     *      * @return     */    public static PrimaryGenerater getInstance() {        if (primaryGenerater == null) {            synchronized (PrimaryGenerater.class) {                if (primaryGenerater == null) {                    primaryGenerater = new PrimaryGenerater();                }            }        }        return primaryGenerater;    }     /**     * 生成下一个编号     */    public synchronized String generaterNextNumber(String sno) {        String id = null;        Date date = new Date();        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");        if (sno == null) {            id = formatter.format(date) + "0001";        } else {            int count = SERIAL_NUMBER.length();            StringBuilder sb = new StringBuilder();            for (int i = 0; i < count; i++) {                sb.append("0");            }            DecimalFormat df = new DecimalFormat("0000");            id = formatter.format(date)                    + df.format(1 + Integer.parseInt(sno.substring(8, 12)));        }        return id;    }}

转载地址:http://iybvi.baihongyu.com/

你可能感兴趣的文章
iWatch报错: Authorizationsession time out
查看>>
X-code7 beta error: warning: Is a directory
查看>>
Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.
查看>>
X-code beta 开发iWatch项目,运行没有错误,但是某些操作一点就崩,而且找不错误的原因场景一
查看>>
Xcode 报错: Extra argument in call
查看>>
iTunes Connect 上传APP报错: Communication error. please use diagnostic mode to check connectivity.
查看>>
#import <Cocoa/Cocoa.h> 报错 Lexical or Preprocessor Issue 'Cocoa/Cocoa.h' file not found
查看>>
`MQTTClient (~> 0.2.6)` required by `Podfile`
查看>>
X-Code 报错 ld: library not found for -lAFNetworking
查看>>
Bitcode
查看>>
If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
查看>>
3.5 YOLO9000: Better,Faster,Stronger(YOLO9000:更好,更快,更强)
查看>>
iOS菜鸟学习--如何避免两个按钮同时响应
查看>>
How to access the keys in dictionary in object-c
查看>>
iOS菜鸟学习—— NSSortDescriptor的使用
查看>>
hdu 3787 hdoj 3787
查看>>
hdu 3790 hdoj 3790
查看>>
hdu 3789 hdoj 3789
查看>>
hdu 3788 hdoj 3788
查看>>
zju 1003 zoj 1003
查看>>