rewind Date To Beginning Of Day - Android java.util

Android examples for java.util:Day

Description

rewind Date To Beginning Of Day

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date rewindToBeginningOfDay(Date date) {
        Calendar cal = buildFromDate(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }/*from w  ww .j  a  v  a 2 s . com*/

    private static Calendar buildFromDate(Date from) {
        Calendar c = Calendar.getInstance();
        c.setTime(from);
        return c;
    }
}

Related Tutorials