get Calendar For Hour And Minus - Android java.util

Android examples for java.util:Hour

Description

get Calendar For Hour And Minus

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static Calendar getCalendarForHourAndMinus(String time) {
        if (null == time) {
            return new GregorianCalendar();
        }/* w w  w  .j a v  a 2 s. c o m*/

        String[] times = time.split(":|??");
        if (times == null || times.length != 2) {
            return new GregorianCalendar();
        }

        int hour = Integer.parseInt(times[0]);
        int minus = Integer.parseInt(times[1]);

        Calendar calendar = new GregorianCalendar();
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minus);
        calendar.set(Calendar.SECOND, 0);
        return calendar;
    }
}

Related Tutorials