获取指定长度随机数和系统当前时间到毫秒
2014-11-14 11:09
399 查看
package org.fenixsoft.osgi.bundle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class testTime {
public static String excute(int length)
{
StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
StringBuffer sb = new StringBuffer();
Random r = new Random();
int range = buffer.length();
for (int i = 0; i < length; i ++)
{
sb.append(buffer.charAt(r.nextInt(range)));
}
return sb.toString();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,0);
Date date = calendar.getTime();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String day=df.format(date);
System.out.println(day);
String res = excute(30);
System.out.println(res);
}
}
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class testTime {
public static String excute(int length)
{
StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
StringBuffer sb = new StringBuffer();
Random r = new Random();
int range = buffer.length();
for (int i = 0; i < length; i ++)
{
sb.append(buffer.charAt(r.nextInt(range)));
}
return sb.toString();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,0);
Date date = calendar.getTime();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String day=df.format(date);
System.out.println(day);
String res = excute(30);
System.out.println(res);
}
}
相关文章推荐
- Linux获取系统当前时间(精确到毫秒)
- Linux获取系统当前时间(精确到毫秒)
- oracle获取当前时间,精确到毫秒并指定精确位数的实现方法
- VB.NET获取系统当前精确时间(毫秒级)
- java获取当前系统时间(最好的方式是取当前系统时间的毫秒数)
- Linux获取系统当前时间(精确到毫秒)
- 获取时间/日期工具类:格式化日期,获取当前时间,指定时间,上一月,指定时间的毫秒数
- Object-C获取系统当前时间(指定格式)
- 两个时间相差多少天/毫秒转天数/天数转毫秒/获取当前系统时间
- 获取系统当前时间的毫秒数
- Linux获取系统当前时间(精确到毫秒)
- C/C++获取当前系统毫秒时间
- C/C++获取当前系统毫秒时间 .
- postgresql获取系统当前时间毫秒数的sql
- 获取当前系统本地时间,精确到毫秒的实例
- JAVA/C/C++获取当前系统毫秒时间+计算程序运行时间
- java 文件压缩 base64加解密 生成指定随机数 时间换算 获取系统 获取mac等小结
- 获取系统当前时间(精确到毫秒)
- 时间操作(Java版)—获取给定时间与当前系统时间的差值(以毫秒为单位)
- Linux获取系统当前时间(精确到毫秒)