Java processing date, on the basis of the specified date plus 5 days, it seems that the Java processing date is much more complex than C #

Source: Internet
Author: User
Tags date1

Import Java.util.Date;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;

public class TestDate {
public static void Main (string[] args) throws Exception {
Creates an object of a date format class that can format strings according to the specified template
SimpleDateFormat f=new SimpleDateFormat ("Yyyy-mm-dd");
Creates a new Date object with the value of the date derived from the string, formatted by F as the date
Date date1 =f.parse ("2005-1-31");
Creates a new Calendar object. Note: Class calendar is abstract to instantiate using getinstance (), or to instantiate its subclasses
Calendar Calen = Calendar.getinstance ();
Calendar object Default date is the current date, call SetTime set the date of the Calendar object to the date specified in the program
Calen.settime (date1);
Increase the calendar's Day by 5
Calen.add (calendar.day_of_year,5);
Gets the time of the Calendar object and assigns it to the Date object C
Date C=calen.gettime ();
Format c with F and output
System.out.println (F.format (c));
}
}

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.