如何从此Hashmap中获取日期
我怎样才能得到变量的目的?
我想要这些数据并将其转换为dateformat。
ArrayList<Map<String, String>> list = buildData();
String[] from = { "name", "purpose" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);
}
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(putData("A", "20.7.2013"));
list.add(putData("B", "21.7.2013"));
list.add(putData("C", "22.7.2013"));
return list;
}
public HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
return item;
}
答案 0 :(得分:0)
您需要使用DateFormat将String转换为Date。 可能是这样的事情可以帮助你
private void getDate(){
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
for( Map<String, String> m : list){
String dateStr = m.get("A");
Date formated = format.parse(dateStr);// This will parse the String i.e. purpose and return the date obj
}
}
EDITED 使用
public HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put(name, purpose);
return item;
}