SimpleDateFormat类中的月份问题 [英] Month issue in SimpleDateFormat class
本文介绍了SimpleDateFormat类中的月份问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String expiryDate = "2016-03-14";
private String formatDateTime(String expiryDate, String expiryTime) {
SimpleDateFormat input = new SimpleDateFormat("yyyy-mm-dd");
SimpleDateFormat output = new SimpleDateFormat("MMM, dd, yyyy");
try {
String formattedDate = output.format(input.parse(expiryDate ));// parse input
return formattedDate + ", " + expiryTime;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
然而,当它返回时,它将于2016年1月14日发布。
However when it returns it gives Jan, 14, 2016.
期望的输出是3月14,2016
The desired output was Mar,14,2016
推荐答案
mm
应为大写 MM
。 Beacuse
mm
should be capital MM
. Beacuse
mm 代表分钟
MM 代表月
所以你的格式应该是
SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd");
这篇关于SimpleDateFormat类中的月份问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文