java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyyMMdd HH:mm");
//DateMaker.getTime(yyyyMMddHHmm);
int year = Integer.parseInt(DateMaker.getTime("yyyy"));
int month = Integer.parseInt(DateMaker.getTime("MM"))-1;
int day = Integer.parseInt(DateMaker.getTime("dd"));
int h = Integer.parseInt(DateMaker.getTime("HH"));
int m = Integer.parseInt(DateMaker.getTime("mm"));
Calendar dateEarliest = new GregorianCalendar(year, month, day, h, m);
dateEarliest.add(Calendar.HOUR, 24);//增加24小時
dateEarliest.roll(Calendar.HOUR, 24);//只改變hour欄位,其他欄位都不動
String dateToday = format.format(dateEarliest.getTime());
System.out.println(dateToday);
4 回應:
public void roll(
int fld,
boolean up);
後面應該是布林值吧....這樣結果會變Double?
abstract void roll(int field, boolean up)//Time Field Rolling function.
void roll(int field, int amount)//Time Field Rolling function.
roll(int field, boolean up)//這個是另一個用法,不會變double,原文說明:Time Field Rolling function. Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
恩恩...我了...只是想確定會不會本來如果 Calendar.Hour = 13 的話, dataEarliest.roll(Calendar.Hour, 24)之後變成 2?
反正差異應該是一個會進位,一個不會進位
一樣+24小時,如果用roll的話,小時部分還是13且日期也不會改變;但如果用add,雖然小時還是13,但日期會加一天。
張貼留言