SmartUpload使用和简介

原文地址为: SmartUpload使用和简介

 

 

 

用以下代码生成文件名即可

 1 package info.haowei.util;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.Random;
6
7 public class IPTimeStamp {
8
9
10 private SimpleDateFormat sdf = null;
11 private String ip = null;
12
13
14 public IPTimeStamp(String ip) {
15 super();
16
17 this.ip = ip;
18 }
19
20
21 public IPTimeStamp() {
22 super();
23 }
24
25
26 public String getIPTimeRand(){
27 StringBuffer buf = new StringBuffer();
28 if(this.ip != null){
29 String s[] = this.ip.split("\\.");//根据ip以点分割将IP中的数字提取
30 for(int i = 0 ; i < s.length; i++){
31 buf.append(this.addZero(s[i], 3));//不够三位数的补零
32 }
33 }
34 buf.append(this.getTimeStamp());
35 Random r = new Random();//再在结尾加上三个随机数
36 for(int i = 0 ; i < 3 ; i++ ){
37 buf.append(r.nextInt(10));
38 }
39 return buf.toString();
40 }
41
42 private String addZero(String str, int len){
43
44 StringBuffer s = new StringBuffer();
45 s.append(str);
46 while(s.length()<len){
47 s.insert(0, 0);
48 }
49
50 return s.toString();
51 }
52
53
54 private String getTimeStamp(){//获取时间戳
55 this.sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
56 return this.sdf.format(new Date());
57 }
58
59 public String getDate(){
60 this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
61 return this.sdf.format(new Date());
62 }
63 }

转载请注明本文地址: SmartUpload使用和简介
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值