首页 > 其他 > 详细

生成时间序列号

时间:2017-07-18 15:09:56      阅读:248      评论:0      收藏:0      [点我收藏+]
package com.myupload.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class IPTimeStamp {
    private SimpleDateFormat sdf = null;
    private String ip = null;
    
    public IPTimeStamp(String ip) {
        this.ip = ip;
    }
    
    public String getIPTimeRand() {
        StringBuffer buf = new StringBuffer();
        if(this.ip != null) {
            String s[] = this.ip.split("\\.");
            for(int i=0; i<s.length; i++) {
                //buf.append(this.addZero(s[i], 3));//这种更复杂一点
                buf.append(s[i]);//ip+时间戳+随机10以内3个数
            }
        }
        buf.append(this.getTimeStamp());
        Random r = new Random();
        for(int i=0; i<3; i++) {
            buf.append(r.nextInt(10));
        }
        return buf.toString();
    }
    
    /*public String addZero(String str, int len) {
        StringBuffer s = new StringBuffer();
        s.append(str);
        while(s.length() < len) {
            s.insert(0, "0");
        }
        return s.toString();
    }*/
    
    public String getDate() {
        this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return this.sdf.format(new Date());
    }
    
    public String getTimeStamp() {
        this.sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return this.sdf.format(new Date());
    }
}

 

生成时间序列号

原文:http://www.cnblogs.com/yunqing/p/7200257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!