Calendar to make a daily judgment in a time period

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.