日期较明显的订单号创建
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()); } }