我刚刚为我的应用程序实现了一个 DatePicker。但我很难理解如何将它('theDate')转换为 SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"),就像我下面代码中的 ('submitDate') 一样。
有人可以告诉我如何在我的代码中做到这一点吗?谢谢!
protected Dialog onCreateDialog(int id) {
switch (id) {
case SDATE_DIALOG_ID:
return new DatePickerDialog(this,
sDateSetListener, mYear, mMonth, mDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener sDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view,
int year, int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDate();
}
};
private void updateDate() {
inputDate.setText(
new StringBuilder()
.append(mMonth + 1).append("-")
.append(mDay).append("-")
.append(mYear).append(" "));
}
class CreateNewRequest extends AsyncTask<String, String, String> {
protected String doInBackground(String... args) {
Calendar c = Calendar.getInstance();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
String submitDate = sd.format(c.getTime());
String theDate = inputDate.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("request_date", theDate));
params.add(new BasicNameValuePair("submitDate", submitDate));
}