3 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
更新:誤解了問題:
Calendar cal = Calendar.getInstance()
cal.set(Calendar.HOUR_OF_DAY,18);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.DATE,2);
cal.set(Calendar.MONTH,9); //Month -1
//Or to set it from a String:
String string = "02/10/19";
DateFormat format = new SimpleDateFormat("dd/MM/yy", Locale.getDefault());
Date date = format.parse(string);
cal.setTimeInMillis(date.getTime());
new DatePickerDialog(getContext(),date1, cal
.get(Calendar.YEAR), cal .get(Calendar.MONTH),
cal .get(Calendar.DAY_OF_MONTH)).show();

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊
字符串是一個(gè)字符數(shù)組。這意味著您可以創(chuàng)建一個(gè)循環(huán)并將不同的日、月和年值設(shè)置為字符串的不同部分。
String date = "02/19/19";
String year = "";
for(int i = 0; i < date.length; i++)
{
month += date.charAt(i);
...
}
然后,當(dāng)它遇到“/”時(shí),你會(huì)告訴它何時(shí)從添加月份切換到添加日期到年份
if(date.charAt(i) == '/')
{
...
}
在這一切的最后,如果你需要將它變成一個(gè) int 那么
int month = Integer.parseInt("month");
抱歉,我要去某個(gè)地方,所以我不能只為你寫出代碼,但我相信你可以從我給你的內(nèi)容中找出答案。

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊
以下代碼對(duì)我來說效果很好:
new DatePickerDialog(Activityclass.this, date1, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show();
DatePickerDialog.OnDateSetListener date1 = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
view.setMinDate(1559327400);
y = year;
m = month;
d = dayOfMonth;
dateMonth = month + 1;
dateYear = year;
iqp_editDate.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
try {
epoch = new java.text.SimpleDateFormat("MM/dd/yyyy").parse(m + "/" + dayOfMonth + "/" + year).getTime() / 1000;
} catch (ParseException e) {
e.printStackTrace();
}
}
};
添加回答
舉報(bào)