我想要一个字符串:例:XM101117001,XM101117002等,其中,XM是固定字母,10是年11是月17是日,这个好办,就是001,002,003。是根据每次调时要增加的,还有如果日期到了第二天,如101118时,还要从001开始,不知道这个001如何生成递增!!!请高手指点!!!

解决方案 »

  1.   

    select max(subStr(code,9,3)) from table where code like 'XM (日期串)%'
    有结果 的时候转整+1 再 补 0
    没结果 设为001
      

  2.   


    private static Date date = null;
    private static int count = 0; public static void main(String[] args) {
    Date d = new Date();
    for (int i = 0; i < 10; i++) {
    if (i == 4) {
    d = new Date();
    }
    get(d);
    }
    } private static void get(Date d) {
    if (date == null) {
    date = d;
    } else {
    if (date != d) {
    count = 0;
    date = d;
    }
    }
    System.out.println(count++);
    }
      

  3.   

    如果某一天的计数超过了3位该怎么办呢? 如 999 都用完了后怎么算?
    如果不考虑这个的话可不可以这么做
    写一个单例,只有一个方法就是获得数字
    Single{
      private int temp = 0;
      public int getID(int num){
        if(num * 1000 > temp){
          temp = num * 1000 + 1;
        }else{
          temp++;
        }
        return temp;
      }
    }
    参数就传如 101117 这样的时间转换过来的一个数字
      

  4.   


    public class Test {
    String str="XM";
    public static void main(String[] args) {

    SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
    Date now=new Date();
    StringBuffer last=new StringBuffer();
    last.append("XM").append(sdf.format(now)).append("000");

    for (int i = 0; i <30; i++) {
    int a=0;
    ++a;
    String aa="";
    if((aa+a).length()==1){
    System.out.println(last.replace(10, 11, (aa+a)));

    }else if((aa+a).length()==2){
    System.out.println(last.replace(9, 11, (aa+a)));
    }
    }
    }不知道这样可不可以,各位大牛给看看
      

  5.   

    最好要引入数据库机制,把用到的日期和产生的最大编号都存起来, 用sql语句去取,取出编号,要把编号用到的信息日期和产生的最大编再存到数据库