无法将15分钟添加到00:00

Aru*_*mar 2 java android

我已经编写了一个以24小时格式添加时间的功能,如下所示

for (int i = 0; i < cursor.getCount(); i++) {

        String RevisedTime="00:00";     



        // 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);



    }

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("kk:mm");
        String date = sdf.format(calendar.getTime());
        return date;
    }
Run Code Online (Sandbox Code Playgroud)

问题是,在00:00加入15分钟时,我得到的输出为12.15 ....

我需要在00:15得到它......请帮助我......

krt*_*tek 5

你必须使用0-23小时格式,而不是1-24.

而不是SimpleDateFormat sdf = new SimpleDateFormat("kk:mm"); 使用SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");