2016-08-21 2 views
0

현재 출력을 얻으려면 DateUtils.getRelativeTimeSpanString을 사용하고 있습니다.DateUtils.getRelativeTimeSpanString 적절한 결과가 없습니다.

8 minutes ago 
8 hours ago 

대신 반환합니다. 내 코드는 다음과 post

In 4 hr 
In 5 hr 

정확히 것은 여기에 내 코드

long postTime = getDateInMillis(pubDate); 
CharSequence time = DateUtils.getRelativeTimeSpanString(System.currentTimeMillis(),postTime,DateUtils.MINUTE_IN_MILLIS,DateUtils.FORMAT_ABBREV_RELATIVE); 

내 getDateInMillis 방법

public static long getDateInMillis(String srcDate) { 

    SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z",Locale.getDefault()); 

    long dateInMillis = 0; 
    try { 
     Date date = formatter.parse(srcDate); 
     dateInMillis = date.getTime(); 
     return dateInMillis; 
    } 

    catch (java.text.ParseException e) { 
     e.printStackTrace(); 
    } 

    return 0; 
} 

날 내가 원하는 올바른 형식을 받고 도와주세요입니다. 감사.

답변

0

내 바보 같은 실수.

가 발생하는 이유는 내가 System.currentTimeMillis(),의 위치를 ​​전환하고 postTime 다음은 올바른 형식을 반환이 줄

CharSequence time = DateUtils.getRelativeTimeSpanString(System.currentTimeMillis(),postTime,DateUtils.MINUTE_IN_MILLIS,DateUtils.FORMAT_ABBREV_RELATIVE); 

때문이었다.

관련 문제