2011-08-10 60 views

回答

1

下面是一個例子,應該幫助你:

Calendar today = Calendar.getInstance(); 
Calendar expireDate = Calendar.getInstance(); 

expireDate.set(2011, Calendar.AUGUST, 12); 

if (today.compareTo(expireDate) == 0 || today.compareTo(expireDate) == 1) 

{ 
// expired - please purchase app 

} 
else 
{ 
// do some stuff 
} 

要判斷它是上午還是下午使用:

int value = today.get(Calendar.AM_PM); 

或者你可以只得到一小時:

int hour = today.get(Calendar.HOUR); 

然後把在if語句:

if (hour > 12) 
{ 

// do stuff 

} 
else 
{ 
// do other stuff 
} 
0

現在時間是可用

new Date() 

解析,對於時間,你可以計算出,如果是設備AM或PM本地時間。

1

您將在這裏得到的時間在24個小時內format.So你可以做你喜歡

final Calendar cld = Calendar.getInstance(); 

      int time = cld.get(Calendar.HOUR_OF_DAY); 
    if(time>12){ 
    //noon 

    }else{ 
    // 
    } 
1
Calendar now = Calendar.getInstance(); 
if (now.get(Calendar.AM_PM) == Calendar.AM) { 
    System.out.println("AM: Before noon"); 
} else { // == Calendar.PM 
    System.out.println("PM: After noon"); 
} 
相關問題