Android Date Interval Get getTimeRangeStr(Date startDate, Date endDate)

Here you can find the source of getTimeRangeStr(Date startDate, Date endDate)

Description

Returns "22:00 - 23:00" for params "2014-02-09 22:00" and "2017-12-31 23:00"

Parameter

Parameter Description
startDate range start
endDate range end

Return

range str

Declaration

public static String getTimeRangeStr(Date startDate, Date endDate) 

Method Source Code

//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    final static DateFormat HOUR_DATE_FORMAT = new SimpleDateFormat("HH:mm");

    /**//  ww w .  j a  v  a 2s .  c o  m
     * Returns "22:00 - 23:00" for params "2014-02-09 22:00" and "2017-12-31 23:00"
     *
     * @param startDate range start
     * @param endDate   range end
     * @return range str
     */
    public static String getTimeRangeStr(Date startDate, Date endDate) {
        return getTimeStr(startDate) + " - " + getTimeStr(endDate);
    }

    /**
     * Returns "22:00" for param "2014-02-09 22:00"
     *
     * @param date the datetime
     * @return time str
     */
    public static String getTimeStr(Date date) {
        return HOUR_DATE_FORMAT.format(date);
    }
}

Related

  1. checkIsIntervalDay(String startTime, String endTime)
  2. totalDays(Object o)
  3. calculatorDaysAgo(String date, Locale locale, String format)
  4. getFirstInterval(Context context, long lastupdate, long updateinterval)
  5. timeDifference(Date date)
  6. formatDuration(int duration)
  7. calcTimeBetween(Date start, Date end)
  8. getOffectDay(long date1, long date2)
  9. getOffectDay(long date1, long date2)