Sets the time fields (24-hour, minute, second, millisecond) of the specified GregorianCalendar instance to 0 so it subsequently represents midnight of the same day as before. - Java java.util

Java examples for java.util:Minute

Description

Sets the time fields (24-hour, minute, second, millisecond) of the specified GregorianCalendar instance to 0 so it subsequently represents midnight of the same day as before.

Demo Code

/**/*  w  ww.j a va2  s .c  o m*/
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */
//package com.java2s;
import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    /**
     * Sets the time fields (24-hour, minute, second, millisecond) of the specified
     * {@link GregorianCalendar} instance to 0 so it subsequently represents midnight
     * of the same day as before.
     * @param c the instance to modify
     */
    public static void setTimeToMidnight(GregorianCalendar c) {
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
    }
}

Related Tutorials