我正在尝试从 Datepicker 获取日期,我的代码如下
dpResult = (DatePicker) findViewById(R.id.dpResult);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Calendar current = Calendar.getInstance();
gettingDate();
}
private void gettingDate() {
// TODO Auto-generated method stub
int day = dpResult.getDayOfMonth();
int month= dpResult.getMonth();
int year = dpResult.getYear();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
formatedDate = sdf.format(new Date(year, month, day));
// You can parse the String back to Date object by calling
try {
date = sdf.parse(formatedDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), ""+formatedDate, 1000).show();
}
});
我的吐司正确显示日期-月份,但在年份的前两位数字为 39 即像 3913,3914 等请帮助我