Java Date to Time getTimeOnly(Date date)

Here you can find the source of getTimeOnly(Date date)

Description

Returns time without date information.

License

Open Source License

Parameter

Parameter Description
date date to be adjusted

Return

Returns date object without time information

Declaration

public static Date getTimeOnly(Date date) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/* w  w  w. ja v a2s.  c  o  m*/
     * Returns time without date information.
     *
     * @param date date to be adjusted
     * @return Returns date object without time information
     */
    public static Date getTimeOnly(Date date) {

        if (null == date) {
            date = new Date();
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.YEAR, 0);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 0);

        return calendar.getTime();
    }
}

Related

  1. getTimeLocalWithoutDst(java.util.Date d)
  2. getTimeMargin(String dateTime)
  3. getTimeMax(Date date)
  4. getTimeOfDate(Date date)
  5. getTimeOnly(Date date)
  6. getTimeOnly(final Date oDate)
  7. getTimePart(Date dateObject)
  8. getTimePeriod(Date date)
  9. getTimerDate(String time)