2011-05-03 63 views
0
Date g=new Date(2011-1900, 3, 2); 
    int y1=g.getYear(); 
    int m1=g.getMonth(); 
    int d1=g.getDay(); 

回答

2

getDay()是從0到6的星期幾。嘗試g.getDate()。儘管這些方法已被廢棄,但僅供參考。

3

你有,你可以用它來得到這樣

Date g=new Date(2011-1900, 3, 2); 
Calendar cal=Calendar.getInstance(); 
cal.setTime(g); 
int month=cal.get(Calendar.MONTH)+1; 
int day=cal.get(Calendar.DAY_OF_MONTH); 
int year=cal.get(Calendar.YEAR); 

價值不應使用 getYear(),getMonth(),getDate() and getDay()方法,因爲它們depracated爲doc says

+0

+1爲理念Date對象。我用舊的棄用方法弄了差不多1個小時,以得到我的結果。你的代碼幫助了我。謝謝.. – YuDroid 2012-08-01 12:02:33

相關問題