- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTimeUtils.java
More file actions
Latest commit
76 lines (60 loc) · 2.19 KB
/
Copy pathTimeUtils.java
File metadata and controls
76 lines (60 loc) · 2.19 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
65
66
67
68
69
70
71
72
73
74
75
76
packagecom.realmo.utils;
importjava.text.DateFormat;
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.Date;
/**
* Created by Administrator on 2017/1/12.
*/
publicclassTimeUtils {
publicstaticStringFROMAT_CN_NO_TIME = "yyyy-MM-dd";
publicstaticStringdateToString(Datedate, StringdateFormat) {
Stringstr;
//String dateFormat = context.getString(R.string.format_date_full);
DateFormatformat = newSimpleDateFormat(dateFormat);
str = format.format(date);
// if (type.equals("SHORT")) {
// // 07-1-18
// format = DateFormat.getDateInstance(DateFormat.SHORT);
// str = format.format(date);
// } else if (type.equals("MEDIUM")) {
// // 2007-1-18
// format = DateFormat.getDateInstance(DateFormat.MEDIUM);
// str = format.format(date);
// } else if (type.equals("LONG")) {
// // 2007-1-18
// format = DateFormat.getDateInstance(DateFormat.LONG);
// str = format.format(date);
// }else if (type.equals("FULL")) {
// // 2007年1月18日 星期四
// format = DateFormat.getDateInstance(DateFormat.FULL);
// str = format.format(date);
// }
returnstr;
}
publicstaticDatestringToDate(Stringstr, StringdateFormat) {
DateFormatformat = newSimpleDateFormat(dateFormat);
Datedate = null;
try {
// Fri Feb 24 00:00:00 CST 2012
date = format.parse(str);
} catch (ParseExceptione) {
e.printStackTrace();
}
// 2012-02-24
//date = java.sql.Date.valueOf(str);
returndate;
}
publicstaticStringstandard(StringstrDate, Stringfrom, Stringto) {
StringtoDate = null;
Datedate = stringToDate(strDate, from);
toDate = dateToString(date, to);
returntoDate;
}
// public static void main(String[] args) {
// Date date = new Date();
// System.out.println(StringOrDate.dateToString(date, "MEDIUM"));
// String str = "2012-2-24";
// System.out.println(StringOrDate.stringToDate(str));
// }
}