我在我的应用程序中创建了一个DatePicker。但是我要克服的问题是如何获取选择的日期并将其存储在数据库中:在我的数据库中,日期字段设置为TEXTprivate int mYear, mMonth, mDay, mHour, mMinute; @Override public void onClick(View v) { final Calendar calendar = Calendar.getInstance(); //Get the date if (v == buttonDatePicker) { mYear = calendar.get(Calendar.YEAR); mMonth = calendar.get(Calendar.MONTH); mDay = calendar.get(Calendar.DAY_OF_MONTH); DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { etDate.setText(dayOfMonth + "-" + month + "-" + year); mYear = year; mMonth = month; mDay = dayOfMonth; } }, mYear, mMonth, mDay); datePickerDialog.show(); } //Get the time if (v == buttonTimePicker) { mHour = calendar.get(Calendar.HOUR_OF_DAY); mMinute = calendar.get(Calendar.MINUTE); } }我试图将选择的Year等从int转换为String,但是当我尝试对其进行转换时,它似乎并不喜欢它。我如何尝试将其存储在我的数据库中: typedUpSmsMessage = smsMessage.getText().toString(); ContentValues cv = new ContentValues(); cv.put("textMessage", typedUpSmsMessage); cv.put("dateToSendText",mYear + mMonth + mDay); cv.put("gameID", gameID); automateGameDB.insert("automateGames", null, cv);但是当然,因为日期是整数,所以它只是加上了数字。是否需要将它们转换为字符串或日期格式?(yyyy-mm-dd hh-mm-ss)?
添加回答
举报
0/150
提交
取消