Java 日期与数字转换
1 package ;
2 import ;
3 import ;
4 import ;
5 import ;
6
7 /**
8 * @author ceshi
9 * @Title: SimpleDate
10 * @Package test
11 * @Description: SimpleDate
12 * @date 2018/5/3016:32
13 */
14 public class JunitSimpleDate {
15
16 public static String DATE_YYYY_MM_DD = "yyyy-MM-dd";
17
18 public static String DATE_Y_M_DDHHMMSS = "yyyy-MM-dd HH:mm:ss";
19
20 @Test
21 public void test() {
22 (convert2long("2018-05-30",DATE_YYYY_MM_DD));
23 (convert2String(curTimeMillis(),DATE_Y_M_DDHHMMSS));
24 }
25
26 /**
27 * 将日期格式的字符串转换为长整型
28 * @param date
29 * @param format
30 * @return
31 */
32 public static long convert2long(String date, String format) {
33 try {
34 if ((date)&&(format)) {
35 SimpleDateFormat sf = new SimpleDateFormat(format);
36 return (date).getTime();
37 }
38 } catch (Exception e) {
39 ();
40 }
41 return 0l;
42 }
43
44 /**
45 * 将长整型数字转换为日期格式的字符串
46 * @param time
47 * @param format
48 * @return
49 */
50 public static String convert2String(long time, String format) {
51 if (time > 0l&&(format)) {
52 SimpleDateFormat sf = new SimpleDateFormat(format);
53 Date date = new Date(time);
54 return (date);
55 }
56 return "";
57 }
58
59 /**
60 * 获取当前系统的日期
61 * @return
62 */
63 public static long curTimeMillis() {
64 return ();
65 }
66
67
68 }