Tips for Date reduction

Source: Internet
Author: User
Just think my contract what how long time expires, the number of fingers feel too tired, feel that write a program can also practice practicing, here GregorianCalendar and Calendar use is the same, just want to try more.
Import Java.util.Calendar;
Import Java.util.GregorianCalendar;

public class calculatedate ... {

public static void Main (string[] args) ... {
GregorianCalendar now = new GregorianCalendar ();
Calendar finish = Calendar.getinstance ();

Finish.set (2007, Calendar.november, 20);

int dayofyear = Now.get (calendar.day_of_year);
int finishday = Finish.get (calendar.day_of_year);

System.out.println (Finishday-dayofyear + "");

}

}

Quoted below: http://article.pchome.net/196711.html

In Calendar, you define the members of the calendars, such as: year, month, day, including different methods of recording, for example: On the same day (2005-12-14), we can say that it is Wednesday of the week, the 14th of December, the first * * * * in 2005. (You can count your own) days. This is a different method of recording, so there are different definitions in the calendar:

Public final static int ERA = 0;
Public final static int year = 1;
Public final static int MONTH = 2;
Public final static int week_of_year = 3;
Public final static int week_of_month = 4;
Public final static int DATE = 5;
Public final static int day_of_month = 5;
Public final static int day_of_year = 6;
Public final static int day_of_week = 7;
Public final static int day_of_week_in_month = 8;
Public final static int am_pm = 9;
Public final static int HOUR = 10;
Public final static int hour_of_day = 11;
Public final static int MINUTE = 12;
Public final static int SECOND = 13;

These definitions are the identification of different recording methods, which I do not enumerate completely, interested you can look at the source code of the calendar.
These are the field of the calendar, according to your different needs can go to different field, different record method is also different filed, this should be good to understand some.
With this, we can get whatever you want, and if you want to know what day of the year it is, you can use:
int day = Calendar.get (calendar.day_of_year);
Parameters are the field you want to get, all of which are defined in the calendar.
The results will tell us that 2005-12-14 is the No. 348 day of 2005.
Then you want to know what the date is 30 days later.
Calendar.set (calendar.day_of_year, day + 30);
In this, you don't have to consider 12-14 plus 30 days is January, is not going to go wrong, will not, calendar itself know that day is a few months date.

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.