2014-12-14 4 views
-2

내가 요구 사항이있는, 내가의 startDate (27JUL14)와 endDate (30JUN15), 및 dayOfWeek (4, 5, 6)주 날짜와 주 일 둘 사이의 날짜

일을 제공 할 수 있습니다 주 대표 -

1 - Monday 
2 - Tuesday 
3 - Wednesday 
4 - Thursday 
5 - Friday 
6 - Saturday 
7 - Sunday 

startDateendDate 사이의 기간은 6개월 긴, 나는 01를 제공 일치하는 모든 특정 날짜를 얻을 필요 시간 간격에 대한은 StartDateEndDate 사이입니다.

public void calculateScheduleDates(Date periodOfOperationFrom, Date periodOfOperationTo, String dow) 
{ 
     String[] weekDays = dow.replaceAll("\\[", "").replaceAll("\\]", "").split(","); 

      int[] dayOfWeek = new int[weekDays.length]; 

      for (int i = 0; i < weekDays.length; i++) 
      { 
       try 
       { 
       dayOfWeek[i] = Integer.parseInt(weekDays[i]); 

       dateTime = (DateTime) DateTime.now().withDayOfWeek(dayOfWeek[i]); 

       System.out.println("DateTime :\t"+dateTime); 

       } 
       catch (NumberFormatException nfe) {}; 
      } 
} 

나는

public void getWeekDate(String beginDate, String finishDate) 
    { 
     System.out.println("Begindate "+ beginDate + "\t EndDate \t"+finishDate); 

     LocalDate startDate = new LocalDate(2014, 12, 1); 
     LocalDate endDate = new LocalDate(2015, 6, 30); 

/* These are date format for startDate and endDate which are not working with 27JUL14 format. 
    This also needs to be changed 
*/ 
     LocalDate thisMonday = startDate.withDayOfWeek(DateTimeConstants.MONDAY); 

     if (startDate.isAfter(thisMonday)) 
     { 
      startDate = thisMonday.plusWeeks(1); // start on next monday 
     } 
     else 
     { 
      startDate = thisMonday; // start on this monday 
     } 

     while (startDate.isBefore(endDate)) 
     { 
      dates.add(startDate); 

      startDate = startDate.plusWeeks(1); 
     } 

     System.out.println("Size of List Of Date :\t"+dates+"\n"+dates.size()); 

} 

지금은 나무 상자 scheduleDates에 시도 (주 일 시작) 주를 얻기 위해 노력했다 :

public void calculateFlightLegScheduleDates(LocalDate[] periodOfOperationFrom, String dow) 
    { 
     /* 
     * Process as per the Weeks received from dates list and set it to current week and process 
     * alongwith dow and for each date, loop in to set the schedule Record. 
     * */ 

     // the incoming weeks "periodOfOperationFrom" in list format, and I need to set the week starting date to the weeks start dates even in future and find the week dates from the dow parameter. This is the point where I am facing challenge. 

    } 

나는 자바에서이 솔루션이 필요합니다.

jodatime 라이브러리를 사용하려고했지만 특정 결과를 얻을 수 없습니다.

참고 : 언급 된 기간 사이에 특정 일수가 필요합니다.

도와주세요.이게 많이 필요합니다.

+0

당신이 더 나은 이해를 위해 샘플을 제공 할 수 있습니까? – Jens

답변

0

하나의 가능성 :

  • 구문 분석 startDate/endDate
  • 이 원하는의 dayOfWeek에게 다음 7 일 추가 endDate에 도달 할 때까지 반복 간과 날짜
  • 인쇄 행진 startDate에서 첫 번째 날짜를 찾을 수 있습니다.

샘플 코드 :

public class App { 

    public static void main(final String[] args) { 
     calculateScheduleDates("27JUL14", "30JUN15", DateTimeConstants.MONDAY); 
    } 

    private static void calculateScheduleDates(final String startDate, final String endDate, final int dayOfWeek) { 
     final DateTimeFormatter formatter = DateTimeFormat.forPattern("ddMMMy").withLocale(Locale.US); 
     final LocalDate end = LocalDate.parse(endDate, formatter); 
     LocalDate start = LocalDate.parse(startDate, formatter); 

     // find the first matching date 
     while (start.getDayOfWeek() != dayOfWeek) { 
      start = start.plusDays(1); 
     } 

     // compute and print results 
     while (start.compareTo(end) < 0) { 
      System.out.println(start.toString(formatter).toUpperCase()); 
      start = start.plusDays(7); 
     } 
    } 
} 

출력 :

28JUL14 
04AUG14 
... 
15DEC14 
22DEC14 
... 
22JUN15 
29JUN15 
+0

답장을 보내 주셔서 감사합니다. 이것은 Week Starting Dates를 찾는 것에 관한 것입니다. 나는 그것을 발견 할 수 있었다. 나의 도전은 주 시작 날짜를 찾은 후, 다우 (4,5,6) 4 - 목요일, 5 - 금요일, 6 - 토요일을 사용하여 그주의 요일을 찾아야한다는 것입니다. 그 주간의 날짜는 일정을 잡는 데 필요합니다 ..! 오는 문자열입니다. –