我想獲得一個時間戳的時間,但我不斷得到錯誤的時間,當我使用Calendar.HOUR
和Calendar.MINUTE
,不管它是什麼時間戳它告訴我小時是10和分鐘是12.日曆給我錯誤的小時和分鐘
現在當我使用Calendar.getTime()
它給了我正確的時間,所以我不明白?我只是想在12小時格式的小時和分鐘
這是我如何去這樣做
public static String getRealTime(long time){
Calendar cal = Calendar.getInstance();
Log.d("Calendar",String.valueOf(time));
cal.setTimeInMillis(time);
Date timeS = cal.getTime();
String sTime = timeS.toString(); // gives correct time in 24hr format
int hr = cal.HOUR; // gives me 10 no matter what the timestamp is
int min = cal.MINUTE; // gives me 12 no matter what the timestamp is
String dMin = getDoubleDigit(min);
int ampm = cal.AM_PM;
String m = new String();
if(ampm == 0){
m = "AM";
}else{
m="PM";
}
String rtime = String.valueOf(hr)+":"+dMin+" "+m;
return rtime;
}
這麼說時間戳1316626200000
cal.getTime()給了我Wed Sep 21 13:30:00 EDT 2011
這將是正確的時間,但cal.HOUR
給我10
小時,這顯然不是它應該是。爲什麼這樣做?
上得到了現在的感謝 – tyczj
大幫了我很多:) –