-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTimeUtils.java
More file actions
76 lines (60 loc) · 2.19 KB
/
TimeUtils.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
package com.realmo.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by Administrator on 2017/1/12.
*/
public class TimeUtils {
public static String FROMAT_CN_NO_TIME = "yyyy-MM-dd";
public static String dateToString(Date date, String dateFormat) {
String str;
//String dateFormat = context.getString(R.string.format_date_full);
DateFormat format = new SimpleDateFormat(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);
// }
return str;
}
public static Date stringToDate(String str, String dateFormat) {
DateFormat format = new SimpleDateFormat(dateFormat);
Date date = null;
try {
// Fri Feb 24 00:00:00 CST 2012
date = format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
// 2012-02-24
//date = java.sql.Date.valueOf(str);
return date;
}
public static String standard(String strDate, String from, String to) {
String toDate = null;
Date date = stringToDate(strDate, from);
toDate = dateToString(date, to);
return toDate;
}
// 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));
// }
}