Soh*_*ziz 2 android date simpledateformat
我试图将日期字符串格式化为Date,然后从中获取月/日:
String strDate="2013-05-15T10:00:00-07:00";
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss-z");
Date convertedDate = new Date();
try {
convertedDate = dateFormat.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdfmonth = new SimpleDateFormat("MM/dd");
String monthday= sdfmonth.format(convertedDate);
Run Code Online (Sandbox Code Playgroud)
但它返回我当前的月/日,即5/18。怎么了?
3件事:
----------更新
String strDate = "2013-05-15T10:00:00-0700";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Date convertedDate = new Date();
try {
convertedDate = dateFormat.parse(strDate);
SimpleDateFormat sdfmonth = new SimpleDateFormat("MM/dd");
String monthday = sdfmonth.format(convertedDate);
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2458 次 |
| 最近记录: |