我正在使用下面的代码将数据和时间格式化为时间,但是任何人都无法帮助我解决此问题,这是行不通的。
try {
String actualDate = m.getDate();//get date as"28-aug-2015 6:46:32 pm"
Date Date= new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").parse(actualDate);
convertDate = new SimpleDateFormat("h:mm a").format(Date);//6:46 am
}
catch (ParseException e) {
e.printStackTrace();
}
转换格式后,我的“ convertDate”值为“ 6.46 am”,但现在的时间为“ 6:46 pm”,我该如何解决此问题。
您那里有一些错误,这就是您想要的:
Date date= new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").parse(actualDate);
convertDate = new SimpleDateFormat("H:mm").format(date);
如果您使用上午/下午,则:
Date date= new SimpleDateFormat("dd-MMM-yyyy h:mm:ss a").parse(actualDate);
convertDate = new SimpleDateFormat("h:mm a").format(date);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句