Android Date to String Convert getHourInFloat(Date date)

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

Description

Converts "2013-09-08 15:30" to 15.5

Return

hour in float

Declaration

public static float getHourInFloat(Date date) 

Method Source Code

import org.apache.commons.lang3.time.DateUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TreeSet;

public class Main{
    /**//from  w ww.j  a va2  s .  c om
     * Converts "2013-09-08 15:30" to 15.5
     *
     * @return hour in float
     */
    public static float getHourInFloat(Date date) {
        final long hours = DateUtils.getFragmentInHours(date,
                Calendar.DAY_OF_MONTH);
        final long minutes = DateUtils.getFragmentInMinutes(date,
                Calendar.HOUR_OF_DAY);

        return hours + (minutes / 60.f);
    }
}

Related

  1. getDateByFormatedString(String date)
  2. getDateTimeString(Date date)
  3. getDateTimeString(Date date, int format, Locale currentLocale)
  4. getFileName()
  5. getFormatString(Date date, String dateFormat)
  6. getLongDateStr(Date date)
  7. getLongFormat(Date date)
  8. getShortDateTimeString(Date date)
  9. getShortFormat(Date date)