2013-10-08 3 views
0

선생님 "08-25-2013"과 같은 날짜가 있습니다.이 문자열 날짜에서 일수를 얻었으므로 이제는 요일과 같은 며칠을 추가합니다. = days +250; 지금 질문은 "05-02-2014"와 같은 날짜를 문자열로 가져 오는 방법입니다. 최대한 빨리 답변 해주십시오. 미리 감사드립니다. Qustions : 날짜로 변환 할 일 수. 이 방법을 수행날짜 입력 일수 Android

+0

이 나는 ​​일의 수를 추가 할 그나마 그것의 간단하고 작동 잘 – Developer

+0

감사 Gaurav 펜디 교수 –

답변

2

..

Calendar c = Calendar.getInstance(); 
    int mYear = c.get(Calendar.YEAR); 
    int mMonth = c.get(Calendar.MONTH); 
    int mDay = c.get(Calendar.DAY_OF_MONTH); 

    // display the current date 
    String CurrentDate = mYear + "/" + mMonth + "/" + mDay; 

    String dateInString = CurrentDate; // Start date 
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 

    c = Calendar.getInstance(); 

    try { 
     c.setTime(sdf.parse(dateInString)); 
    } catch (ParseException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    c.add(Calendar.DATE, 7656);//insert the number of days you want to be added to the current date 
    sdf = new SimpleDateFormat("dd/MM/yyyy"); 
    Date resultdate = new Date(c.getTimeInMillis()); 
    dateInString = sdf.format(resultdate); 

    //Display the Result in the Edit Text or Text View your Choice 
    EditText etDOR = (EditText)findViewById(R.id.etDateOfReturn); 
    etDOR.setText(dateInString); 
+0

선생님을 게시 한 코드를 시도 코드 현재 날짜로, 나는 사용자로부터 입력으로 날짜를 취할 것이고 그것은 과거 날짜가 될 것입니다. 안내 날짜는 08, 25,2013, 구름이 될 수 있습니다. 04-01-2013, 12-31-2012 –

+0

i 위의 날짜에 일수를 더해야합니다 –

+0

그 다음에 s 대체 할 c.setTime (sdf.parse (dateInString)); 귀하의 날짜 문자열과 함께 작동하지만 날짜 형식을 알고 있어야합니다. –

0

사용

  SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); 
     Date dateparsed = sdf.parse("29-08-2013"); 
     Calendar c = Calendar.getInstance(); 
     c.setTime(dateparsed); 
     c.add(Calendar.DATE, 250); // Adding n number of days 
     String output = sdf.format(c.getTime()); 
     System.out.println(output); 
+0

제 질문에 대답 해 주신 Gaurav Pandey에게도 감사드립니다. –

+0

친애하는 D : D – Developer