Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    public static AtomicInteger reqSerialNum = new AtomicInteger(0);

    public static String getReqSerial() {
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMddHHmmss");
        return dateformat.format(new Date()) + genReqSerialNum() + "05";
    }

    public static String genReqSerialNum() {
        if (reqSerialNum.get() == 99999999) {
            reqSerialNum.set(0);
        }
        int newValue = reqSerialNum.incrementAndGet();

        StringBuilder result = new StringBuilder(Integer.toString(newValue));
        int len = result.length();
        for (int i = len; i <= 8; i++) {
            result.insert(0, "0");
        }
        return result.toString();
    }
}