Java gets the day after the current date __java

Source: Internet
Author: User

Given a date, how do I get the day after this date? This is not a simple current date plus one thing. On the last day of the year, the last day of the month will be transferred to the next one months, which will make a mistake. Here is a simple way to use the method provided by the Calendar class. Words are not more directly on the code.

public static string Getthenextdate (String date) {//201711191600 if (date!=null&&date.lengt
		H () >=8) {date=date.substring (0, 8);
		}else {return "";
		} String year=date.substring (0,4);
		String month=date.substring (4,6);
		String day1=date.substring (6,8);
		System.out.println (year+ "" +month+ "" +day1);
		String datestr=year+ "-" +month+ "-" +day1;
		Date Mydate=null;
		Calendar calendar=calendar.getinstance ();
		try {mydate=new SimpleDateFormat ("Yyyy-mm-dd"). Parse (DATESTR);
		catch (ParseException e) {e.printstacktrace ();
		} calendar.settime (MyDate);
		int Day=calendar.get (calendar.date);
		Calendar.set (Calendar.date, day+1);
		String dayafter=new SimpleDateFormat ("Yyyy-mm-dd"). Format (Calendar.gettime ());
		System.out.println (Dayafter);
		String [] Datearray=dayafter.split ("-");
		String dayafter1= "";
		for (int i = 0; i < datearray.length i++) {dayafter1+=datearray[i];
	return dayAfter1; }
The landlord test, copy can be used.


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.