Java Calendar Time setTime(Calendar cal, String time)

Here you can find the source of setTime(Calendar cal, String time)

Description

set Time

License

Open Source License

Declaration

public static void setTime(Calendar cal, String time) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static void setTime(Calendar cal, String time) {
        int hour = 0;
        int minute = 0;
        int idx = time.indexOf(':');
        if (idx < 0) {
            hour = Integer.parseInt(time);
        } else {//ww  w .  ja v  a  2 s .  c om
            hour = Integer.parseInt(time.substring(0, idx));
            time = time.substring(idx + 1);
            idx = time.indexOf(':');
            if (idx < 0) {
                minute = Integer.parseInt(time);
                idx = 1;
            } else {
                minute = Integer.parseInt(time.substring(0, idx));
                idx = Integer.parseInt(time.substring(idx + 1));
            }
        }
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        cal.set(Calendar.SECOND, idx);
    }
}

Related

  1. resetTime(GregorianCalendar cal)
  2. roundTime(double dt, Calendar tmp)
  3. sameTime(Calendar one, Calendar two)
  4. setDateTimeByString(Calendar theDateTime, String str)
  5. setTime(Calendar cal, int h, int m, int s, int ms)
  6. setTime(final Calendar calendat, final String[] test)
  7. setTimeFrom(Calendar c)
  8. setTimeTo0(final Calendar calendar)
  9. setTimeToMidnight(GregorianCalendar c)