我写了一个添加时间的功能,如下所示
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,hour,minute); calendar.add(Calendar.MINUTE,minutesToAdd); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm"); String date = sdf.format(calendar.getTime()); return date; }
我正在从01:10得到这个爆发,从12点开始…
我需要得到它的13:10格式,即24小时格式…..请帮助我
解决方法
您在SimpleDateFormat模式中使用了hh.这是12小时的格式.使用kk代替,这样可以让您以24小时格式显示当天的时间.见
SimpleDateFormat.