我是java 学习者
我现在想用JAVA生成字符串 例如2007053101
其中前面的部分用 JAVA 语言调用系统日期生成 例如上面的20070531
后两位为编号 例如2007053101中的01  如果01存在 就生成02 (2007053102)
由于本人学习java 时间尚短 水平有限 现在急需使用 
恳求各位的帮助!
如果不喜欢把代码发到帖子中 可以发到我邮箱 [email protected]
在线等!!!
万分感激!!!

解决方案 »

  1.   

    new SimpleDateFormat("yyyyMMdd").format(new Date())
    01、02去哪儿判断呀……
      

  2.   

    public class GenDateStr
        {
    public String genSequence(int num ,int length)
    {
        String result = "";
        String numStr = String.valueOf(num);
        if(numStr.length()>length)
    return numStr;
        int cnt = length-numStr.length();
        for(int i=0;i<cnt;i++)
    {
        result+="0";
    }
        return result+numStr;
    } /**
     * @param args
     */
    public static void main(String[] args)
    {
        GenDateStr genDateStr = new GenDateStr();
        java.util.Date date = new java.util.Date();
        java.text.SimpleDateFormat s = new java.text.SimpleDateFormat("yyyyMMdd");
        
        for(int i=0;i<100;i++)
    {
        String generatedStr = s.format(date);
        generatedStr+=genDateStr.genSequence(i, 2);
        System.out.println(generatedStr);
    }
    }    }==================================
    输出结果是
    2007053100
    2007053101
    2007053102
    2007053103
    2007053104
    2007053105
    2007053106
    2007053107
    2007053108
    2007053109
    2007053110
    2007053111
    2007053112
    2007053113
    2007053114
    2007053115
    2007053116
    2007053117
    2007053118
    2007053119
    2007053120
    2007053121
    2007053122
    2007053123
    2007053124
    2007053125
    2007053126
    2007053127
    2007053128
    2007053129
    2007053130
    2007053131
    2007053132
    2007053133
    2007053134
    2007053135
    2007053136
    2007053137
    2007053138
    2007053139
    2007053140
    2007053141
    2007053142
    2007053143
    2007053144
    2007053145
    2007053146
    2007053147
    2007053148
    2007053149
    2007053150
    2007053151
    2007053152
    2007053153
    2007053154
    2007053155
    2007053156
    2007053157
    2007053158
    2007053159
    2007053160
    2007053161
    2007053162
    2007053163
    2007053164
    2007053165
    2007053166
    2007053167
    2007053168
    2007053169
    2007053170
    2007053171
    2007053172
    2007053173
    2007053174
    2007053175
    2007053176
    2007053177
    2007053178
    2007053179
    2007053180
    2007053181
    2007053182
    2007053183
    2007053184
    2007053185
    2007053186
    2007053187
    2007053188
    2007053189
    2007053190
    2007053191
    2007053192
    2007053193
    2007053194
    2007053195
    2007053196
    2007053197
    2007053198
    2007053199
      

  3.   

    诶 刚才不是回答了吗
    怎么有问
    SimpleDateFormat simpledateformat;
        simpledateformat = new SimpleDateFormat ("yyyyMMdd");
        Date dt=new Date();
        String strDate=simpledateformat.format(dt);