Java Day Start startOfDay(Date aDate)

Here you can find the source of startOfDay(Date aDate)

Description

start Of Day

License

Apache License

Declaration

public static Date startOfDay(Date aDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private Calendar calendar;
    private static final String COLON = ":";
    private static final String ZERO = "0";

    public static Date startOfDay(Date aDate) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(aDate);/*  w w w  . j  a va  2  s.c o  m*/
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        Date dayBreak = cal.getTime();
        return dayBreak;
    }

    public String getTime() {
        return getHour() + COLON + getMinute();
    }

    public int getHour() {
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public String getMinute() {
        int tempMinute = calendar.get(Calendar.MINUTE);
        return tempMinute < 10 ? ZERO + tempMinute : Integer.toString(tempMinute);
    }
}

Related

  1. startOfDay(Date aDate)
  2. startOfDay(Date date)
  3. startOfDay(Date date)
  4. startOfDay(Date dateInst)