博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
时间格式生成序列【主键】
阅读量:2354 次
发布时间:2019-05-10

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

时间格式生成序列【主键】

public class GenerateSequenceUtil {	     /** .log *///    private static final Logger logger = Logger.getLogger(GenerateSequenceUtil.class);     /** The FieldPosition. */    private static final FieldPosition HELPER_POSITION = new FieldPosition(0);     /** This Format for format the data to special format. */    private final static Format dateFormat = new SimpleDateFormat("MMddHHmmssS");     /** This Format for format the number to special format. */    private final static NumberFormat numberFormat = new DecimalFormat("0000");     /** This int is the sequence number ,the default value is 0. */    private static int seq = 0;     private static final int MAX = 9999;     /**     * 时间格式生成序列     * @return String     */    public static synchronized String generateSequenceNo() {         Calendar rightNow = Calendar.getInstance();         StringBuffer sb = new StringBuffer();         dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);         numberFormat.format(seq, sb, HELPER_POSITION);         if (seq == MAX) {            seq = 0;        } else {            seq++;        } //        logger.info("THE SQUENCE IS :" + sb.toString());         return sb.toString();    }    public static void main(String[] args) {		System.out.println(GenerateSequenceUtil.generateSequenceNo());	}}

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

你可能感兴趣的文章
iOS UINavigationController 详解
查看>>
iOS UIViewController 和 xib 绑定 详解
查看>>
Hue 安装部署 详解
查看>>
Linux 安装Scala 详解
查看>>
MySQL 分支版本对比 详解
查看>>
MyCat 注解 详解
查看>>
MySQL 循环方法 while loop repeat 详解
查看>>
Java 创建对象以及类加载 详解
查看>>
JavaScript 闭包 详解
查看>>
Oracle 基础知识 详解
查看>>
JVM 命令参数 详解
查看>>
Java 产生随机数 详解
查看>>
Linux 后台执行命令 详解
查看>>
SpringBoot @ConfigurationProperties参数绑定 详解
查看>>
Nginx+Lua 开发的 hello world 案例 详解
查看>>
OpenResty 基础知识 和 Linux部署 详解
查看>>
图的一些算法题
查看>>
图的一些算法题2
查看>>
git merge 之后文件被删除
查看>>
队列的一些算法题
查看>>