I'm trying to get the date of tomorrow and insert it into a Date type variable, but for some reason I'm getting an empty string.
Here his the code:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String time_Date_str = cal.getTime().toString();
try
{
Date myDate = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(time_Date_str);
Toast.makeText(this, "time_Date_str", Toast.LENGTH_SHORT).show();
t.setDueDate(myDate);
t.setHasDate(true);
} catch(Exception e){myDate=null;}
Please let me know what I'm doing wrong.
您没有使用sdf
变量设置日期格式...请尝试以下操作:
String time_Date_str = sdf.format(cal.getTime());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.