在添加时间时需要24小时格式的时间

我已经写了一个添加时间的函数,如下所示

private void Delay15Minute() { String pkManifest = manifest.pkManifestNo; manifest_helper = new manifest_helper(this); cursor = manifest_helper.GetDeliveries(pkManifest); cursor.moveToFirst(); for (int i = 0; i < cursor.getCount(); i++) { cursor.getString(cursor.getColumnIndex("PKDelivery")); // String // RevisedTime=cursor.getString(cursor.getColumnIndex("RevisedEstimatedDeliveryTime")); String RevisedTime = "12:55"; // get hour and minute from time string StringTokenizer st1 = new StringTokenizer(RevisedTime, ":"); int j = 0; int[] val = new int[st1.countTokens()]; // iterate through tokens while (st1.hasMoreTokens()) { val[j] = Integer.parseInt(st1.nextToken()); j++; } // call time add method with current hour, minute and minutesToAdd, // return added time as a string String date = addTime(val[0], val[1], 15); // Tioast the new time Toast.makeText(this, "date is =" + date, Toast.LENGTH_SHORT).show(); } } public String addTime(int hour, int minute, int minutesToAdd) { Calendar calendar = new GregorianCalendar(1990, 1, 1, hour, minute); calendar.add(Calendar.MINUTE, minutesToAdd); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm"); String date = sdf.format(calendar.getTime()); return date; } 

我得到了这个01:10作为12小时fromat …

我需要得到13:10格式,即24小时格式…..请帮助我

Solutions Collecting From Web of "在添加时间时需要24小时格式的时间"

你在你的SimpleDateFormat模式中使用了hh 。 那是12小时的格式。 用kk来代替24小时的格式。 请参阅SimpleDateFormat 。

只需创buildCalendar的实例,并获得24小时的时间,

 Calendar c = Calendar.getInstance(); int Hr24=c.get(Calendar.HOUR_OF_DAY); int Min=c.get(Calendar.MINUTE);