Set Calendar by hour of day and minute - Android java.util

Android examples for java.util:Calendar

Description

Set Calendar by hour of day and minute

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    private static Calendar prepareCalendar(int hourOfDay, int minute) {
        Calendar calNow = Calendar.getInstance();
        Calendar calSet = (Calendar) calNow.clone();

        calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
        calSet.set(Calendar.MINUTE, minute);
        calSet.set(Calendar.SECOND, 0);
        calSet.set(Calendar.MILLISECOND, 0);

        if (calSet.compareTo(calNow) <= 0) {
            // Today Set time passed, count to tomorrow
            calSet.add(Calendar.DATE, 1);
        }//from  w w w .jav  a  2 s  .co m
        return calSet;
    }
}

Related Tutorials