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