每秒生成10万订单号
创始人
2024-04-03 19:30:46
0

/**
 * @author: 
 * @date: 2019/12/27
 * @time: 16:54
 * @description:
 */
public class TimeNumberUtils {
    public static void main(String[] args) {
      //测试方法略..自己去测了哈
     //结果: ===>20200407133313000001       
    }

    
private static int sequence = 0;
private static int length = 6;

public static synchronized String getLocalTrmSeqNum() {
    sequence = sequence >= 999999 ? 1 : sequence + 1;
    String datetime = new SimpleDateFormat("yyyyMMddHHmmss")
            .format(new Date());
    String s = Integer.toString(sequence);
    return datetime +addLeftZero(s, length);
    }

    /**
     * 左填0
     * @author shijing
     * 2018年6月29日下午1:24:32
     * @param s
     * @param length
     * @return
     */
public static String addLeftZero(String s, int length) {
        // StringBuilder sb=new StringBuilder();
        int old = s.length();
        if (length > old) {
            char[] c = new char[length];
            char[] x = s.toCharArray();
            if (x.length > length) {
                throw new IllegalArgumentException(
                        "Numeric value is larger than intended length: " + s
                                + " LEN " + length);
            }
            int lim = c.length - x.length;
            for (int i = 0; i < lim; i++) {
                c[i] = '0';
            }
            System.arraycopy(x, 0, c, lim, x.length);
            return new String(c);
        }
        return s.substring(0, length);
    }
}

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...