zoukankan      html  css  js  c++  java
  • 生成时间序列号

    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());
        }
    }
  • 相关阅读:
    java集合
    struts2的OGNL表达式
    struts2 result type
    struts2在Action中访问WEB资源
    03异或^
    02自加自减运算机制
    原码,补码,反码
    Java基础50题test10—自由落体
    Java基础50题test9—求完数
    Java基础50题test8—输入数字求和
  • 原文地址:https://www.cnblogs.com/yunqing/p/7200257.html
Copyright © 2011-2022 走看看