Java Today Today()

Here you can find the source of Today()

Description

Today

License

Open Source License

Return

object representing midnight of the current day

Declaration

public static Date Today() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from   ww  w.ja v  a 2  s  . c o  m
     * @return {@link Date} object representing midnight of the current day
     */
    public static Date Today() {
        return removeTime(new Date());
    }

    /**
     * Sets the time on the given {@link Date} object to midnight
     *
     * @param d
     * @return
     */
    public static Date removeTime(Date d) {
        Calendar inst = GregorianCalendar.getInstance();
        inst.setTime(d);
        inst.set(Calendar.HOUR_OF_DAY, 0);
        inst.set(Calendar.MINUTE, 0);
        inst.set(Calendar.SECOND, 0);
        inst.set(Calendar.MILLISECOND, 0);
        return inst.getTime();
    }
}

Related

  1. parseToday(String s)
  2. plusDaysToday(int days)
  3. sameTimeToday(Date time)
  4. startOfToday()
  5. today()
  6. today()
  7. today()
  8. today()
  9. today()