Information Source: http://zhidao.baidu.com/question/146050582.html?qbl=relate_question_0&word=%C8%A1%B5%C3%B8%F8%B6%A8% Ca%b1%bc%e4%b6%ce%c4%da%b5%c4%ce%c4%bc%fe
Question: How does Java get all the weeks in the specified time period, and what is the weekly geometric date for each day of the week?
The answers are as follows:
Import Java.text.DateFormatSymbols;
Import Java.util.Calendar;
Import Java.util.GregorianCalendar;
public class Test {
/**
* @param args
*/
public static void Main (string[] args) {
Calendar c_begin = new GregorianCalendar ();
Calendar c_end = new GregorianCalendar ();
DateFormatSymbols DFS = new DateFormatSymbols ();
string[] weeks = dfs.getweekdays ();
C_begin.set (2010, 3, 2); Calendar month from 0-11, so April is 3.
C_end.set (2010, 4, 20); Calendar month from 0-11, so May is 4.
int count = 1;
C_end.add (calendar.day_of_year, 1); The end date is rolled down one day to include the last day
while (C_begin.before (c_end)) {
System.out.println ("+count+", "Sunday period:" +new java.sql.Date (C_begin.gettime (). GetTime ()) + "," +weeks[c_begin.get ( Calendar.day_of_week)]);
if (C_begin.get (Calendar.day_of_week) ==calendar.sunday) {
count++;
}
C_begin.add (calendar.day_of_year, 1);
}
}
}
Calendar to make a daily judgment in a time period