DateUtils.java
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.yoho.message.sdk.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Created by chenchao on 2017/1/13.
*/
public final class DateUtils {
public static final String dateConnSeperator="-",
dateFormat = "yyyy-MM-dd",
fullDateTimeFormat = "yyyy-MM-dd HH:mm:ss",
MIN_DateTimeFormat = "yyyy-MM-dd HH:mm",
DateTimeFormat = "yy.MM.dd HH:mm",
d_DateTimeFormat = "yy-MM-dd HH:mm";
public static int getCurrentTimeSeconds() {
long longTime = System.currentTimeMillis();
return (int) (longTime / 1000);
}
public static long getCurrentDateMillis(){
StringBuffer dateStr = new StringBuffer();
Calendar now = Calendar.getInstance();
int year= now.get(Calendar.YEAR);
int month= now.get(Calendar.MONTH) + 1;
int day=now.get(Calendar.DAY_OF_MONTH);
dateStr.append(year).append(dateConnSeperator)
.append(month).append(dateConnSeperator)
.append(day);
DateFormat format = new SimpleDateFormat(dateFormat) ;
long dateTime=0L;
try {
Date nowDate = format.parse(dateStr.toString());
dateTime=nowDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
return dateTime;
}
public static void main(String[] args) {
System.out.println(DateUtils.long2DateStr(1514982989 * 1000l, DateUtils.fullDateTimeFormat));
}
public static String long2DateStr(long time, String format) {
Date date = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat(format);
String dateStr = sdf.format(date);
return dateStr;
}
}