为什么获取的当前时间不对
大神帮看看我写的这个代码为什么获取的当前小时数不对,还有显示的日历总多出一竖列?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.datetime.MainActivity"
android:orientation="vertical">
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date" />
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time" />
</LinearLayout>
.Java文件:
public class MainActivity extends ActionBarActivity {
DatePicker date;
TimePicker time;
int my_year,my_month,my_day,my_hour,my_minute;
Calendar my_calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date=(DatePicker) findViewById(R.id.date);
time=(TimePicker) findViewById(R.id.time);
my_calendar=Calendar.getInstance(Locale.CHINA);
my_year=my_calendar.get(Calendar.YEAR);
my_month=my_calendar.get(Calendar.MONTH);
my_day=my_calendar.get(Calendar.DAY_OF_MONTH);
my_hour=my_calendar.get(Calendar.HOUR_OF_DAY);
my_minute=my_calendar.get(Calendar.MINUTE);
time.setIs24HourView(true);
date.init(my_year,my_month, my_day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
my_year=year;
my_month=monthOfYear;
my_day=dayOfMonth;
}
});
time.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
my_hour=hourOfDay;
my_minute=minute;
}
});
}
}