我想以时间格式转换以下字符串值。
String convertInTime="10:20 AM"
然后我想四舍五入到“11:00 AM ”
我该怎么做?
我不知道你是否可以使用apache commons库,如果可以,请参考:org.apache.commons.lang3.time.DateUtils.round(Date date, int field):
第一个参数是java.util.Date ,您可以在java.text.SimpleDateFormat的帮助下创建它,第二个参数是来自 Calendar 类(如Calendar.HOUR )的常量。
如果您不能使用 apache 公共库,请检查他们是如何做到的: http ://commons.apache.org/proper/commons-lang/javadocs/api-3.1/src-html/org/apache/commons/lang3/时间/DateUtils.html#line.645。