public static String getRandomStringByLength(int length) { String base = "0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(base.length()); sb.append(base.charAt(number)); } return sb.toString(); } /** * @function 生成商户订单号/退款单号 * @date 2015-12-17 * @return String */ public static String getOrderNo(){ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); Date date = new Date(); return sdf.format(date) + getRandomStringByLength(4); }
原文:http://www.cnblogs.com/xrhou12326/p/6623451.html