2011-08-26 7 views
0

이 항목을 사용하여 HTML 항목 목록을 읽습니다.문자열과 달력의 날짜를 비교하는 방법은 무엇입니까?

while (postIt.hasNext()) { 
    Element name = postIt.next(); 
    nameOf = name.text(); 

    String platform = postIt.next().text(); 

    //Get the URL 
    Element url = name.select("a").first(); 
    urlString = url.attr("href"); 

    //Get the Genre of the item 
    String genre = postIt.next().text(); 

    //Get the date 
    Date = postIt.next().text(); 
} 

내가 수행하고 싶은 것은 날짜 문자열을 Android 기기의 현재 날짜와 비교하는 것입니다. 캘린더를 통해 어떻게해야합니까?

답변

4

나는, Date

Date d = new Date(); //todays date (current time) 

//set the pattern here to look like the pattern you are expecting in your 'Date' variable 
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 

String formattedDate = sdf.format(d); 
//for today the string would look like this: "2011-08-26" 

boolean isToday = formattedDate.equals(Date); //your answer... 

SimpleDateFormatter 익숙하지 않은 경우 SimpleDateFormat를 사용하여이 작업을 수행 documentation here을 확인합니다. 패턴을 설정하는 데 유용한 정보가 많이 있습니다.

+0

내가 좋아하는 멋진 소리가 들립니다. 그럼 내가 html에서 찾은 날짜를 위에서 설명한 날짜와 비교할 것인가? – yoshi24

+1

어디 까지나 필요한 것입니다. 위에 게시 한 코드는 거의 모든 곳에 배치 할 수 있습니다. –

+0

알았습니다! 좋습니다. 한 가지 더 ... 2011 년 8 월 26 일에 형식을 설정할 수 있습니까? 나는 문서에서 그것을 보지 못했다. – yoshi24

관련 문제