如何将这种格式的日期转换为mm/dd/yyyy
在yyyy-mm-dd
Android 中将数据保存到 SQLite 数据库时?
问问题
181 次
4 回答
2
然后你可以使用 Calendar 对象。
Calendar cal=Calendar.getInstance();
您可以使用检索相同
long date=cursor.getLong(cursor.getColumnIndex("expired_date"));
Calendar cal=Calendar.getInstance();
cal.clear();
cal.setTimeInMillis(date);
有关各种日期格式,请参阅此链接 http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html
Calendar cal=Calendar.getInstance();
String date_time=String.format("%1$tY %1$tB %1$te,%1$tI:%1$tM:%1$tS %1$Tp",cal);
Toast.makeText(getApplicationContext(),date_time,Toast.LENGTH_SHORT).show();
于 2013-03-12T04:19:51.950 回答
2
SimpleDateFormat new_format= new SimpleDateFormat("yyyy-MM-dd);
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
Date date;
String local_date = null;
try{
date = sdf.parse(value);
local_date = new_format.format(date);
}catch(ParseException e)
{
e.printStackTrace();
}
于 2013-03-12T04:29:02.013 回答
1
看看这段代码..这将解决您有关日期时间转换的所有疑问..
public static String convertDateStringFormat(String currentFormat,
String newFormat, String strDate) {
SimpleDateFormat dateFormat = new SimpleDateFormat(currentFormat);
Date date = null;
try {
date = dateFormat.parse(strDate);
} catch (ParseException e) {
CommonFunctions.DoCatchOperation(e);
}
String newFormatString = convertDateToString(newFormat, date);
return newFormatString;
}
public static Date convertStringToDate(String dateFormatter, String strDate) {
SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatter);
Date date = null;
try {
date = dateFormat.parse(strDate);
} catch (ParseException e) {
CommonFunctions.DoCatchOperation(e);
}
return date;
}
public static String convertDateToString(String dateFormatter, Date date) {
if (date == null)
return "";
else {
SimpleDateFormat dFormat = new SimpleDateFormat(dateFormatter);
return dFormat.format(date);
}
}
于 2013-03-12T04:41:52.030 回答
0
public String formatDate(String value) {
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy",
Locale.US);
Date date;
String dateformat = "";
try {
date = sdf.parse(value);
sdf.applyPattern("yyyy-mm-dd");
dateformat = sdf.format(date);
} catch (Exception e) {
return "";
}
return dateformat;
}
于 2013-03-12T04:09:34.407 回答