Java date: add one day, year, month, and date plus 1, date + 1, month + 1, year + 1, and date

Source: Internet
Author: User

Java date: add one day, year, month, and date plus 1, date + 1, month + 1, year + 1, and date

System. out. println ("String type" + endDate); // The time when the page is passed to the background is String type SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd "); date sDate = sdf. parse (endDate); System. out. println ("String type to Date type" + sDate); // to implement Date + 1, convert String to Date type Format f = new SimpleDateFormat ("yyyy-MM-dd "); system. out. println ("Date end Date:" + f. format (sDate); Calendar c = Calendar. getInstance (); c. setTime (sDate); c. add (Calendar. DAY_OF_MONTH, 1); // use Calendar to implement Date + 1 day sDate = c. getTime (); System. out. println ("Date end Date + 1" + f. format (sDate); // print the Date. The value is displayed successfully + 1 day SimpleDateFormat sdf1 = new SimpleDateFormat ("yyyy-MM-dd"); endDate = sdf1.format (sDate ); system. out. println ("Convert Date type to String type" + endDate); // convert the Date type to String type to facilitate database comparison
String type 2011-1-23string type to Date type Tue Jan 23 00:00:00 CST 2018Date end Date: 2011-1-23date end Date + 1 2011-1-24date type to String type 2011-1-24

 

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.