Java Date to Time getTimeFromDate(final Date date)

Here you can find the source of getTimeFromDate(final Date date)

Description

Create an integer time from a Date object.

License

Open Source License

Parameter

Parameter Description
date The date to get the timestamp from.

Return

The time as an integer formatted as "HHmm".

Declaration

public static int getTimeFromDate(final Date date) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//from  ww  w  .ja  v  a2s .  c om
     * Create an integer time from a <code>Date</code> object.
     *
     * @param date
     *            The date to get the timestamp from.
     * @return The time as an integer formatted as "HHmm".
     */
    public static int getTimeFromDate(final Date date) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        final int hour = calendar.get(Calendar.HOUR_OF_DAY) * 100;
        final int minute = calendar.get(Calendar.MINUTE);
        return hour + minute;
    }
}

Related

  1. getTimeByOffset(Date reqDate, int offset)
  2. getTimeDateByMinuteAndSeconds( Integer minutes, Integer seconds)
  3. getTimeDateStr(Date date)
  4. getTimeDeltaValue(Date t, Date baseDate, String tDelta)
  5. getTimeFromDate(Date date)
  6. getTimeImMillis(Date date)
  7. getTimeInSeconds(Date date)
  8. getTimeInterval(Date fromDate)
  9. getTimeIntervalMins(Date firstDate, Date lastDate)