日期较明显的订单号创建

public class OrderSn {
  
   public static String getOrderSn(){
      return "O"+getNowDate()+getRadom();
   }
  //随机数
   public static String getRadom(){
      return String.format("%04d",new Random().nextInt(9999));
   }
  //格式化时间
   public static String getNowDate() {
      Date currentTime = new Date();
      SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
      String dateString = formatter.format(currentTime);
      return dateString;
   }

   public static void main(String[] args) {
      System.out.println(getOrderSn());
   }
}

 

posted @ 2020-05-11 16:11  ±小马哥  阅读(263)  评论(0编辑  收藏  举报