提交 | 用户 | 时间
|
ce910c
|
1 |
package com.iailab.module.data.dev.hikvision.utils; |
H |
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
import java.util.Date; |
|
5 |
|
|
6 |
public class CommonUtils { |
|
7 |
/** |
|
8 |
*<p>获取当前日期<p> |
|
9 |
*<p>格式yyyyMMdd<p> |
|
10 |
*/ |
|
11 |
public static String getCurrDate(){ |
|
12 |
Date date=new Date(); |
|
13 |
SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMdd"); |
|
14 |
String tDate = df1.format(date); |
|
15 |
return tDate; |
|
16 |
} |
|
17 |
|
|
18 |
/** |
|
19 |
*<p>获取当前时间<p> |
|
20 |
*<p>格式yyyyMMddHHmmss<p> |
|
21 |
*/ |
|
22 |
public static String getCurrDate2(){ |
|
23 |
Date date=new Date(); |
|
24 |
SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
25 |
String tDate = df1.format(date); |
|
26 |
return tDate; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
*<p>获取当前时间<p> |
|
31 |
*<p>格式yyyy-MM-dd HH:mm:ss<p> |
|
32 |
*/ |
|
33 |
public static String getCurrDate3(){ |
|
34 |
Date date=new Date(); |
|
35 |
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
36 |
String tDate = df1.format(date); |
|
37 |
return tDate; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* 由年月日时分秒+3位随机数 |
|
42 |
* 生成流水号 |
|
43 |
* @return |
|
44 |
*/ |
|
45 |
public static Long Getnum(){ |
|
46 |
String t = getCurrDate2(); |
|
47 |
int x=(int)(Math.random()*900)+100; |
|
48 |
String serial = t + x; |
|
49 |
Long num = new Long(serial); |
|
50 |
return num; |
|
51 |
} |
|
52 |
|
|
53 |
//主方法测试 |
|
54 |
public static void main(String[] args) { |
|
55 |
System.out.println(Getnum()); |
|
56 |
} |
|
57 |
} |