Java automatically generates order number + serial number

introduce

This is the journey of the editor's growth path, and also the editor's learning path. Hope to grow up with you guys!

Here are two of my favorite quotes:

To have the most simple life and the most distant dream, even if it will be cold tomorrow, the mountains will be high and the water will be far away, and the road will be far away.

Why should one work hard? The best answer I have ever seen is: because the things I like are expensive, the places I want to go are far away, and the person I love is perfect. Therefore, the editor would like to say: encourage each other! 
 

code:

package com.lyn.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class AutoOrder {
    /**
     * 获取现在时间
     * @return返回字符串格式yyyyMMddHHmmss
     */
    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("YYMMddHHmmss");
        String dateString = formatter.format(currentTime);
        // System.out.println("TIME:::"+dateString);
        return dateString;
    }

    public static String getStringDate1() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("mmss");
        String dateString = formatter.format(currentTime);
        // System.out.println("TIME:::"+dateString);
        return dateString;
    }
    /**
     * 固定资产编号,由年月日时分秒+3位随机数
     * 生成流水号
     * @return
     */
    public static String assetNumber(){
        String t = getStringDate1();
        int x=(int)(Math.random()*90)+10;
        String serial = t + x;
        return serial;
    }

    /**
     * 由年月日时分秒+3位随机数
     * 生成流水号
     * @return
     */
    public static String Getnum(){
        String t = getStringDate();
        int x=(int)(Math.random()*90)+10;
        String serial = t + x;
        return serial;
    }

    /**
     * 由年月日时分秒+3位随机数
     * 生成流水号
     * @return
     */
    public static String Getnum1(){
        String t = getStringDate();
        int x=(int)(Math.random()*9);
        String serial = t + x;
        return serial;
    }



    public static String getTwo() {
        Random rad = new Random();

        String result = rad.nextInt(100) + "";

        if (result.length() == 1) {
            result = "0" + result;
        }
        return result;
    }

    public  static String GetSystemserialnumber() {
        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String seconds = new SimpleDateFormat("HHmmss").format(new Date());
        return "EX" + date + getTwo() + "00" + seconds + getTwo();
    }

    //主方法测试
    public static void main(String[] args) {
        String m= GetSystemserialnumber();
        System.out.println(m);
    }

}

The result of running

 The above is the code used by the editor, I hope it can help everyone, thank you for watching! ! !

Guess you like

Origin blog.csdn.net/weixin_60387745/article/details/130169253