Android 申请日期显示解决方案

Android 申请日期显示解决方案,android,date,textview,Android,Date,Textview,最终字符串消息[]={“”,“”} 试试看{ 字符串UID=null,UBAL=null; DateFormat DateFormat=新的简化格式(“yyyy-MM-dd”); 日历更新; ArrayList后参数=新的ArrayList(); add(新的BasicNameValuePair(“UserID”,id.getId()); response=connection.executehttpost(“http://condoproject.net16.net/PayCheck.php“

最终字符串消息[]={“”,“”}

试试看{
字符串UID=null,UBAL=null;
DateFormat DateFormat=新的简化格式(“yyyy-MM-dd”);
日历更新;
ArrayList后参数=新的ArrayList();
add(新的BasicNameValuePair(“UserID”,id.getId());
response=connection.executehttpost(“http://condoproject.net16.net/PayCheck.php“,后参数);
Toast.makeText(getApplicationContext(),“”+响应,Toast.LENGTH_LONG.show();
JSONArray jArray=新JSONArray(响应);
对于(int i=0;i“PayDate”的格式是什么?您不能将其强制为日历对象。请参阅。您可能想写:

Udate.setText(json_data.getString("PayDate"));

这可能是错误的:

PDate = (Calendar) json_data.get("PayDate");
PDate.add(Calendar.MONTH, 1);  
String P = ""+PDate;
首先,我怀疑从JSONObject到Calendar的转换是否能以这种方式工作。“值可以是JSONObject、其他JSONArray、字符串、布尔值、整数、长、双精度、null或null的任意组合。值不能是NaN、无限或此处未列出的任何类型。”()

尝试:

第二,您无法通过这种方式获取人类可读格式的日期:

String P = ""+PDate;
如果要在日期中添加内容,则必须转换并转换回,例如:

// assuming that the format of your date is "yyyy-MM-dd"
//convert from String to Date
Date myDate = dateFormat.parse(myDateString);
//convert from Date to Calendar
PDate = Calendar.getInstance();
PDate.setTime(myDate);
//this adds 1 month to your Calendar object:
PDate.add(Calendar.MONTH, 1);
//this converts back from Calendar to Date object
myDate = PDate.getTime();
//this converts from Date to String
myDateString = dateFormat.format(myDate);

// and update text
Udate.setText(myDateString );
如果只向PDate添加一个月来补偿它存储从0到11的月值的事实,那么您可以按照Dheeraj所说的那样做

String P = ""+PDate;
// assuming that the format of your date is "yyyy-MM-dd"
//convert from String to Date
Date myDate = dateFormat.parse(myDateString);
//convert from Date to Calendar
PDate = Calendar.getInstance();
PDate.setTime(myDate);
//this adds 1 month to your Calendar object:
PDate.add(Calendar.MONTH, 1);
//this converts back from Calendar to Date object
myDate = PDate.getTime();
//this converts from Date to String
myDateString = dateFormat.format(myDate);

// and update text
Udate.setText(myDateString );