的DatePicker显示月份的错误值错误、DatePicker

2023-09-05 10:13:12 作者:我们终将独自长大

我在的DatePicker 一个问题,Android的,当我使用的getMonth()方法,那么它会返回一个错误值。

I have a problem in DatePicker in android when I use getMonth() method then it will return a wrong value.

例如:

DatePicker datepicker=new DatePicker();

int day=date.getDayOfMonth();
int month=date.getMonth();
int year=date.getYear();

t.setText(""+day+" / "+month+" / "+year);

如果我将选择1987年8月6日,然后将返回1987年6月7日

If I will select aug 06 1987 then it will return 6/7/1987

我认为这是一个错误,如果不告诉我的原因吧。

I think it is an error, if not tell me the reason please.

推荐答案

月被编入索引从0开始,所以八月是8月或索引7,从而给你正确的结果。请参阅Android SDK。

Months are indexed starting at 0, so August is month 8, or index 7, thus giving you the correct result. See Android SDK.

 
精彩推荐
图片推荐