Gets the number of weeks that are included in Java for 2 time periods (week of stock, from Saturday to Friday)

Source: Internet
Author: User

The Calendar class was started on the first day of Sunday, so Calendar.day_of_week is 1 when it was Sunday.

In the stock there is a day K week K and the month K data.

The week k in this refers to the data for the week of the trading day, which is a cycle from Saturday to Friday.

1 /**2 * Returns the number of stock weeks between 2 dates3      * @paramstartdate 2012-02-01 Start date4      * @paramendDate 2014-02-01 End Date5      * @return6      */7      Public Static  intgetstockweeks (String startdate,string endDate) {8         intA = 0;9         Try {TenSimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd"); OneCalendar before =calendar.getinstance (); ACalendar after =calendar.getinstance (); -Calendar temp =calendar.getinstance (); -              the Before.settime (Sdf.parse (StartDate)); - After.settime (Sdf.parse (endDate)); -              -             LongTime1 =before.gettime (). GetTime (); +             LongTime2 =after.gettime (). GetTime (); -              +             if(time1>time2) {//the start and end times are reversed (it is possible that the time is wrong) Atemp=before; atBefore=After ; -After=temp; -             } -              -             intWeek =Before.get (calendar.day_of_week); -              inBefore.add (Calendar.date,-week);//not Monday for first day of Saturday for first day -              toWeek =After.get (calendar.day_of_week); +              -             if(week>0&&week<7) After.add (calendar.date, 6-week); the             if(week==7) After.add (calendar.date, 6); *A= (int) ((After.gettimeinmillis ()-before $. Gettimeinmillis ())/Const_week);Panax NotoginsengA = A-1; -             if(A = = 0) { theA = 1; +             } A}Catch(Exception e) { the e.printstacktrace (); +         } -         returnA; $     } $     

Gets the number of weeks that are included in Java for 2 time periods (week of stock, from Saturday to Friday)

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.