The JAVA input date is the day of the week to calculate

Source: Internet
Author: User
Tags date1

// Enter the date to get the day of the week
Public String getweekday (string datestr ){
Simpledateformat formatymd = new simpledateformat ("yyyy-mm-dd"); // formatymd indicates the yyyy-mm-dd format.
Simpledateformat formatd = new simpledateformat ("e"); // "E" indicates "Day in week"
Date d = NULL;
String weekday = "";
Try {
D = formatymd. parse (datestr); // convert string to a date in the correct format
Weekday = formatd. Format (d );
} Catch (exception e ){
E. printstacktrace ();
}
// System. Out. println ("Date:" + datestr + ":" + weekday );
Return weekday;
}

 

// Calculate the date in the middle of two time periods
Public String [] [] finddates (string start_time, string end_time) throws parseexception {
Simpledateformat df = new simpledateformat ("yyyy-mm-dd ");
Date date1 = DF. parse (start_time );
Date date2 = DF. parse (end_time );
Int S = (INT) (date2.gettime ()-date1.gettime ()/(24*60*60*1000 ));
String value [] [] = new string [S + 1] [1];
If (S + 1> 0 ){
For (INT I = 0; I <= s; I ++ ){
Long todaydate = date1.gettime () + I * 24*60*60*1000;
Date tmdate = new date (todaydate );
Value [I] [0] = new simpledateformat ("yyyy-mm-dd"). Format (tmdate );
// System. Out. println (New simpledateformat ("yyyy-mm-dd"). Format (tmdate ));
}
}
Return value;
}

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.