-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateUtil.java
More file actions
45 lines (35 loc) · 1.47 KB
/
DateUtil.java
File metadata and controls
45 lines (35 loc) · 1.47 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
package mining_software_repositories;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
// util for converting date types
public class DateUtil {
// date format in Jira report
public static final String DATE_TIME_FORMAT_E_DD_MMM_YYYY_HHMMSS = "E dd MMM yyyy HH:mm:ss";
public static final String DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_TIME_FORMAT_YYYYMMDD = "yyyyMMddHHmmss";
// parse string date to long
public static long parseStrToLong(String date, String timeFromat) throws Throwable {
String _date = date.replace("+0000", "").replace(",", "").trim();
DateFormat dateFormat = new SimpleDateFormat(timeFromat);
return dateFormat.parse(_date).getTime();
}
public static String parseDateToStr(Date time, String timeFromat) {
DateFormat dateFormat = new SimpleDateFormat(timeFromat);
return dateFormat.format(time);
}
public static void main(String[] args) {
String str1 = "Fri, 18 Apr 2014 23:21:23 +0000";
String str2 = "Wed, 21 May 2014 02:03:46 +0000";
String str3 = "2009-12-23 03:33:13 +0000";
try {
//long l1 = parseStrToLong(str1, DATE_TIME_FORMAT_E_DD_MMM_YYYY_HHMMSS);
long l = parseStrToLong(str3, DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS);
//long l = l2 - l1;
Date d = new Date(l);
System.out.println(parseDateToStr(d, DATE_TIME_FORMAT_YYYYMMDD));
System.out.println(l/1000/60/60/24);
} catch(Throwable t) {
}
}
}