Java隨機生成訂單表號,當前時間+隨機五位數


package cn.gov.csrc.util;

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

public class RandomUtil {

 /**   * 生成隨機文件名:當前年月日時分秒+五位隨機數   *   * @return   */  public static String getRandomFileName() {

  SimpleDateFormat simpleDateFormat;

  simpleDateFormat = new SimpleDateFormat("yyyyMMdd");

  Date date = new Date();

  String str = simpleDateFormat.format(date);

  Random random = new Random();

  int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 獲取5位隨機數

  return rannum + str;// 當前時間  }

 public static void main(String[] args) {

  String fileName = RandomUtil.getRandomFileName();

  System.out.println(fileName);//8835920140307  } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM