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)