欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java生成时间戳,java生成

来源: javaer 分享于  点击 10122 次 点评:119

java生成时间戳,java生成


 

java生成时间戳

分类: Java
[java] view plaincopyprint?
  1. package cn.mldn.lxh.util;  
  2. import java.text.SimpleDateFormat;  
  3. import java.util.Date;  
  4. import java.util.Random;  
  5. public class IPTimeStamp {  
  6.     private SimpleDateFormat sdf = null;  
  7.     private String ip = null;  
  8.     public IPTimeStamp(){  
  9.                       
  10.     }  
  11.     public IPTimeStamp(String ip){  
  12.         this.ip = ip;         
  13.     }  
  14.     public String getIPTimeRand(){  
  15.         StringBuffer buf = new StringBuffer();  
  16.         if(this.ip!=null){  
  17.             String s[] = this.ip.split("\\.");  
  18.             for(int i=0;i<s.length;i++){  
  19.                 buf.append(this.addZero(s[i],3));       //不够三位数字的要补0                  
  20.             }  
  21.         }  
  22.         buf.append(this.getTimeStamp());            //取得时间戳  
  23.         Random r = new Random();  
  24.         for(int i=0;i<3;i++){  
  25.             buf.append(r.nextInt(10));              //增加一个随机数         
  26.         }  
  27.         return buf.toString();  
  28.     }  
  29.     private String addZero(String str,int len){  
  30.         StringBuffer s = new StringBuffer();  
  31.         s.append(str);  
  32.         while(s.length()<len){  
  33.             s.insert(0,"0");              
  34.         }  
  35.         return s.toString();  
  36.     }  
  37.     public String getDate(){  
  38.         this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");  
  39.         return this.sdf.format(new Date());  
  40.     }  
  41.     public String getTimeStamp(){  
  42.         this.sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");  
  43.         return this.sdf.format(new Date());  
  44.     }  
  45. }  

相关文章

    暂无相关文章
相关栏目:

用户点评