有没有在android中添加时间的功能?

时间:2011-08-12 11:10:52

标签: android

我从09:30开始从数据库中检索时间,我需要加上15分钟才能得到它作为09:45。 是否有添加时间的功能?

4 个答案:

答案 0 :(得分:1)

String RevisedTime=cursor.getString(cursor.getColumnIndex("RevisedEstimatedDeliveryTime"));     

            // 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++;
            }`enter code here`

            // call time add method with current hour, minute and minutesToAdd,
            // return added time as a string
            String dateRevisedEstimatedDeliveryTime = 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("HH:mm");
        String date = sdf.format(calendar.getTime());
        return date;
    }

答案 1 :(得分:0)

答案 2 :(得分:0)

试试这个

    final Calendar cld = Calendar.getInstance();
    cld.setTimeInMillis(time);
   cld.add(Calendar.MINUTE,15)

答案 3 :(得分:0)

使用Calendar.add(Calendar.MINUTE,15)来获取