gpt4 book ai didi

android - 添加时间时需要以 24 小时格式获取时间

转载 作者:可可西里 更新时间:2023-11-01 18:49:14 26 4
gpt4 key购买 nike

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

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;
}

我从 12 小时后的 01:10 开始接收这个信息......

我需要以 13:10 格式获取它,即 24 小时格式......请帮助我

最佳答案

您在 SimpleDateFormat 模式中使用了 hh。那是 12 小时格式。请改用 kk,它以 24 小时格式为您提供一天中的小时数。参见 SimpleDateFormat .

关于android - 添加时间时需要以 24 小时格式获取时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com