Java自动生成订单编号+流水号

介绍

这里是小编成长之路的历程,也是小编的学习之路。希望和各位大佬们一起成长!

以下为小编最喜欢的两句话:

要有最朴素的生活和最遥远的梦想,即使明天天寒地冻,山高水远,路远马亡。

一个人为什么要努力? 我见过最好的答案就是:因为我喜欢的东西都很贵,我想去的地方都很远,我爱的人超完美。因此,小编想说:共勉! 
 

代码:

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);
    }

}

运行的结果

 以上就是小编所使用到的代码,希望能够帮到大家,感谢各位大佬的观看!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值