get Date With Time To Mid night - Java java.util

Java examples for java.util:Calendar Calculation

Description

get Date With Time To Mid night

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Date date = new Date();
        System.out.println(getDateWithTimeToMidnight(date));
    }/*from   w  w  w.jav a2  s  . c  om*/

    public static Date getDateWithTimeToMidnight(Date date) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);

        return cal.getTime();

    }
}

Related Tutorials