java生成时间戳,java生成
分享于 点击 10122 次 点评:119
java生成时间戳,java生成
java生成时间戳
分类: Java[java] view plaincopyprint?
- package cn.mldn.lxh.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(){
- }
- 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)); //不够三位数字的要补0
- }
- }
- buf.append(this.getTimeStamp()); //取得时间戳
- Random r = new Random();
- for(int i=0;i<3;i++){
- buf.append(r.nextInt(10)); //增加一个随机数
- }
- return buf.toString();
- }
- private 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());
- }
- }
相关文章
- 暂无相关文章
用户点评