发布网友 发布时间:2022-04-24 11:33
共3个回答
热心网友 时间:2023-10-11 08:02
等下帮你写
public static void main(String[] args) {
long id=1001;
StringBuffer sb = new StringBuffer();
sb.append(LongToFixLengthString(id));
sb.append(" ");
SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmm");
sb.append(df.format(new Date()));
sb.append(" ");
Random random = new Random();
sb.append(random.nextInt(100)+10);
System.out.println(sb.toString());
}
public static String LongToFixLengthString(long id) {
NumberFormat formatter = new DecimalFormat("000000");
return formatter.format(id);
}追问急用啊 速度 谢了
追答改成 sb.append(random.nextInt(90)+10);
热心网友 时间:2023-10-11 08:02
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class Test {
public static void main(String[] args) {
int id = 123;
System.out.println(getStr(id));
}
public static String getStr(int id){
StringBuilder sb = new StringBuilder();
sb.append(id);
while(sb.length() < 6){
sb.insert(0, "0");
}
sb.append(new SimpleDateFormat("yyMMddHHmm").format(new Date()));
int number = new Random().nextInt(100);
if(number < 10){
sb.append(0);
}
sb.append(number);
return sb.toString();
}
}
--------testing
000123120223151746
热心网友 时间:2023-10-11 08:03
String id="113";
SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmm");
String time = sdf.format(new Date());
String rand = (int)(Math.random()*100)+"";
String res = id+" "+time+" "+rand;
for(int i =0;i<=21-res.length();i++)
{
res = "0"+res;
}
System.out.println(res);