更改日期格式存储为字符串 [英] Changing date format stored as a String
本文介绍了更改日期格式存储为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我以以下格式将日期存储在数据库中
Currently I store a date in my database in the following format
dbTimestamp = new SimpleDateFormat("yyyy-MM-dd").format(myCalendar.getTime());
我希望通过光标将这些信息提取出来,并以以下格式显示给用户
I am looking to pull this information in a cursor and display it to the user in the following format
String newTimestamp = new SimpleDateFormat("MM/dd/yyyy").format(date);
我如何将其从2014-07-31转换为2014年7月31日?
How would I go about converting it from 2014-07-31 to 07/31/2014?
我尝试使用
String transactionDate = cursor.getString(cursor.getColumnIndex("timestamp"));
String newTimestamp = new SimpleDateFormat("MM/dd/yyyy").format(transactionDate);
但是我收到以下错误:错误的类:class java.lang.String
But i get the following error: Bad class: class java.lang.String
推荐答案
try {
String reformattedStr = new SimpleDateFormat("dd/MM/yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-31"));
} catch (ParseException e) {
e.printStackTrace();
}
这篇关于更改日期格式存储为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文