-
Notifications
You must be signed in to change notification settings - Fork 1
/
DateUtils.java
104 lines (84 loc) · 2.19 KB
/
DateUtils.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class DateUtils
{
public static final String YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMMDD = "yyyy-MM-dd";
public static String formatDate(Date date, String format)
{
return formatDateByFormat(date, format);
}
/**
* 验证时间是否落在系统配置的用户允许登录的时间段内
*
* @param dateValue 时间字符串
*
* @return
*/
public static String parseDate(String dateValue)
{
}
public static String formatDate(Date date)
{
}
public static boolean isToday(String checkDate)
{
Date date = stringToDate(checkDate, "yyyy-MM-dd");
formatDate(date, "yyyy-MM-dd");
return formatDate(new Date(), "yyyy-MM-dd").equals(formatDate(date, "yyyy-MM-dd"));
}
private static String formatDateByFormat(Date date, String format)
{
String ret = "";
if (date != null)
{
SimpleDateFormat sdf = new SimpleDateFormat(format);
ret = sdf.format(date);
}
return ret;
}
public static Date string2Date(String str, String format)
{
if (str != null)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try
{
return dateFormat.parse(str);
} catch(ParseException e)
{
return null;
}
} else
{
return null;
}
}
public static void main(String[] args)
{
List<String> ret = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
Date startDate = string2Date("2011-02-19 13:12:06", YYYYMMDDHHMMSS);
calendar.setTime(startDate);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date endDate = string2Date("2011-3-05 23:59:59", YYYYMMDDHHMMSS); //结束时间
while (calendar.getTime().getTime() <= endDate.getTime())
{
Date d = calendar.getTime();
String day = formatDate(d, YYYYMMDD);
ret.add(day + "(上午)");
ret.add(day + "(下午)");
calendar.roll(Calendar.DAY_OF_YEAR, 1); //明天
}
for (String str : ret)
{
System.out.println(str);
}
}
}