日期:2014-05-18 浏览次数:20717 次
private static int temp = 0;
public static String getNum(){
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String date = df.format(new Date());//获取当前时间yyyymmdd格式
String str ;
if(temp<10){
str = "0"+temp;
}else{
str = ""+temp;
}
String num = date + str;
temp ++;
return num;
}
public class Test {
private static AtomicInteger num = new AtomicInteger(1);
public static void main(String[] args) throws Exception {
Integer year = Calendar.getInstance().get(Calendar.YEAR);
//月份从0开始
Integer month = Calendar.getInstance().get(Calendar.MONTH) + 1;
String monthStr = (month < 10)?"0"+month.toString():month.toString();
Integer day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
String dayStr = (day < 10)?"0"+day.toString():day.toString();
String time = year.toString() + monthStr + dayStr;
//输出100个
while(num.intValue() <= 100){
Integer i = num.getAndIncrement();
System.out.println(time + i.toString());
}
}
}