2017-01-05 1 views
-2

이 나는 ​​형태로 JSON 개체날짜 형식을 수정하는 방법은 무엇입니까?

내가 2017-01-05이 날짜 형식을 변환 할 필요가
Sun Jan 08 00:00:00 GMT+05:30 2017. 

있어 날짜 형식이 문제 에 대한 해결책을 찾기 위해 도와주세요.

가 나는 루프에 입력 할 수없는 생각이

android.text.format.DateFormat df = new android.text.format.DateFormat(); 
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
Date date1 = simpleDateFormat.parse(summary1.getDeliveryDate()); 
if(date1.equals(df.format("yyyy-MM-dd", new java.util.Date()))) 
{ 
     spinnerArray.add("Cancel"); 
} 

같은 일부 코드를 구현 ... 솔루션

+0

이 [링크] 참조 (http://stackoverflow.com/questions/14039062/how-to-convert-date-in-to-yyyy-mm-dd-format) –

답변

0

샘플 코드

String inputDate = "2017-01-05 00:00:00"; 
    System.out.println("Input Date: "+inputDate); 
    String pattern = "yyyy-MM-dd"; 
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); 
    Date formatDate = simpleDateFormat.parse(inputDate); 
    String outputDate = simpleDateFormat.format(formatDate); 
    System.out.println("Output Date: " +outputDate); 

을 찾아 도와주세요 출력 :

Input Date: 2017-01-05 00:00:00 
Output Date: 2017-01-05 

알려 주시기 바랍니다.

+0

를 I는 다음과 같이 쓸 때 "summary1.getDeliverydate()" "2017-01-05 00 : 00 : 00.0"과 같은 날짜 형식이 있습니다. "00 : 00 : 00.0"을 제거하고 싶습니다. – NareshY

+0

위 코드를 확인하십시오. 그것은 당신의 문제를 해결할 것입니다. – Avijit

+0

summary1.getDeliverydate()를 변수에 저장하고 변수의 데이터 유형을 확인한 다음 위에서 언급 한 로직을 적용하십시오. – Avijit

0

아마도이 방법이 유용 할 수 있습니다.

Date date1 = summary1.getDeliveryDate(); 
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); 
if(fmt.format(date1).equals(fmt.format(new Date()))) 
{ 
    spinnerArray.add("Cancel"); 
} 
관련 문제