需要有时间在24小时格式,同时增加时间 [英] Need get Time in a 24 hour format while adding Time
本文介绍了需要有时间在24小时格式,同时增加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写一个函数,其将时刻如下给出
I had written a function for Adding time as given below
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;
}
我收到的这个oupt为01:10 12小时fromat ...
I am getting the oupt of this as 01:10 as 12 hours fromat...
我需要得到它在13:10格式即在24小时制.....请帮我
I need to get it in 13:10 format ie 24 hour format.....Please help me
推荐答案
您在的SimpleDateFormat
模式中使用 HH
。那是12小时制。使用 KK
代替,这为您提供了一个24小时制的一天的时间。请参阅<一href="http://developer.android.com/reference/java/text/SimpleDateFormat.html">SimpleDateFormat.
You used hh
in your SimpleDateFormat
pattern. Thats the 12 hour format. Use kk
instead, that gives you the hours of the day in a 24 hour format. See SimpleDateFormat.
这篇关于需要有时间在24小时格式,同时增加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文