Uda*_*ran 10 java android date
我有日期的字符串形式:
2011-03-27T09:39:01.607
Run Code Online (Sandbox Code Playgroud)
我想格式化它 March 27, 2011
我在用
DateFormat[] formats = new DateFormat[] {
DateFormat.getDateInstance(), DateFormat.getDateTimeInstance(),
DateFormat.getTimeInstance(), };
String actDate= formats[0].format(uploadeddate.substring(0,9));
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我如何转换为March 27, 2011?
Nir*_*tel 13
试试这个
SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
java.util.Date date = null;
try
{
date = form.parse("2011-03-27T09:39:01.607");
}
catch (ParseException e)
{
e.printStackTrace();
}
SimpleDateFormat postFormater = new SimpleDateFormat("MMMMM dd, yyyy");
String newDateStr = postFormater.format(date);
Run Code Online (Sandbox Code Playgroud)
现在 newDateStr = March 27, 2011;
Mud*_*sir 10
可能是这有任何帮助;
String convertDate(String inputDate) {
DateFormat theDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = theDateFormat.parse(inputDate);
} catch (ParseException parseException) {
// Date is invalid. Do what you want.
} catch(Exception exception) {
// Generic catch. Do what you want.
}
theDateFormat = new SimpleDateFormat("MMM dd, yyyy");
return theDateFormat.format(date);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11225 次 |
| 最近记录: |