/** */
/**
**对时间周的处理 传入{"2008-05-25","2008-07-5"},返回{2008-6-23,2008-6-29,2008-6-30,2008-7-6}******
*/
public
static
String[] getBeginAndEndWeek(String dateBeg,String dateEnd)
{
String temp
=
""
;
String[] tempArr
=
null
;
Date begin
=
formatDate(dateBeg);
GregorianCalendar date1
=
new
GregorianCalendar();
date1.setTime(begin);
int
DAY_OF_WEEK1
=
date1.get(GregorianCalendar.DAY_OF_WEEK);
if
(DAY_OF_WEEK1
==
2
)
{
}
else
{
int
changeDay
=
DAY_OF_WEEK1
-
2
;
if
(changeDay
==-
1
) changeDay
=
6
;
date1.set(GregorianCalendar.DATE, date1.get(Calendar.DATE)
-
changeDay);
}
Date end
=
formatDate(dateEnd);
GregorianCalendar date2
=
new
GregorianCalendar();
date2.setTime(end);
int
DAY_OF_WEEK2
=
date2.get(GregorianCalendar.DAY_OF_WEEK);
if
(DAY_OF_WEEK2
==
1
)
{
}
else
{
int
changeDay
=
8
-
DAY_OF_WEEK2;
date2.set(GregorianCalendar.DATE, date2.get(Calendar.DATE)
+
changeDay);
}
GregorianCalendar date3
=
new
GregorianCalendar();
date3.setTime(date1.getTime());
date3.add(Calendar.DATE,
-
1
);
if
(date1.compareTo(date2)
==-
1
)
{
temp
=
temp
+
formatDate(date1.getTime())
+
"
,
"
;
date1.add(Calendar.DATE,
7
);
date3.add(Calendar.DATE,
7
);
while
(date1.compareTo(date2)
==-
1
)
{
temp
=
temp
+
formatDate(date3.getTime())
+
"
,
"
+
formatDate(date1.getTime())
+
"
,
"
;
date3.add(Calendar.DATE,
7
);
date1.add(Calendar.DATE,
7
);
}
temp
=
temp
+
formatDate(date2.getTime())
+
"
,
"
;
}
else
{
date2.setTime(date1.getTime());
date2.add(Calendar.DATE,
6
);
temp
=
formatDate(date1.getTime())
+
"
,
"
+
formatDate(date2.getTime())
+
"
,
"
;
}
if
(temp.length()
>
1
)
{
tempArr
=
temp.split(
"
,
"
);
for
(
int
i
=
0
; i
<
tempArr.length; i
++
)
{
System.out.println(tempArr[i]);
}
}
return
tempArr;
}
public
static
Date formatDate(String date)
{
Date d1
=
new
Date();
if
(date
==
null
||
date.equals(
""
))
return
new
Date();
try
{
DateFormat df
=
new
SimpleDateFormat(
"
yyyy-MM-dd
"
);
d1
=
df.parse(date);
}
catch
(Exception ex)
{
}
return
d1;
}
posted on 2008-06-25 22:36
crazy 阅读(89)
评论(0) 编辑 收藏 所属分类:
java