如何从班级中检索“日期”类型。我需要先将其更改为String吗? 我可以获得String类型和布尔类型但不能从我的数据库中获取日期/时间。
点击图片示例: http://i.imgur.com/FcvO1R5.png
我的代码:
public class AttendanceList extends Activity{
private TextView code;
private TextView name;
private TextView section;
private TextView date;
String subcode;
String subname;
String subsection;
// Date subdate;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendance_list);
code=(TextView)findViewById(R.id.sub_code);
name=(TextView)findViewById(R.id.sub_name);
section=(TextView)findViewById(R.id.sub_section);
date=(TextView)findViewById(R.id.date);
ParseQuery<ParseObject> query=ParseQuery.getQuery("TME2301");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> parseObjects, ParseException e) {
if(e==null){
for(ParseObject object:parseObjects){
subcode=object.getString("Subject_code");
subname=object.getString("Subject_name");
subsection=object.getString("Subject_section");
//subdate=object.getDate("date");
code.setText(subcode);
name.setText(subname);
section.setText(subsection);
}
}
}
});
}}
答案 0 :(得分:0)
java.util.Date subdate;
try {
subdate=object.getDate("date");
DateFormat df = new SimpleDateFormat("MMM dd, yyyy, kk:mm", Locale.ENGLISH);
String subdateStr = df.format(subdate);
date.setText(subdateStr);
} catch(Exception ex) {
// log error
}