Java Day End secondsToEndOfDay(Date aDate)

Here you can find the source of secondsToEndOfDay(Date aDate)

Description

seconds To End Of Day

License

Apache License

Declaration

public static Long secondsToEndOfDay(Date aDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private Calendar calendar;
    private static final String COLON = ":";
    private static final String ZERO = "0";

    public static Long secondsToEndOfDay(Date aDate) {
        Date midnight = endOfDay(aDate);
        return timeDifferenceInSeconds(aDate, midnight);
    }/*from  www .  jav  a2  s  .com*/

    public static Date endOfDay(Date aDate) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(aDate);
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.HOUR_OF_DAY, 24);
        Date midnight = cal.getTime();
        return midnight;
    }

    public static Long timeDifferenceInSeconds(Date startDate, Date endDate) {
        if (startDate == null || endDate == null) {
            return null;
        }
        return (endDate.getTime() - startDate.getTime()) / (1000L);
    }

    public String getTime() {
        return getHour() + COLON + getMinute();
    }

    public int getHour() {
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public String getMinute() {
        int tempMinute = calendar.get(Calendar.MINUTE);
        return tempMinute < 10 ? ZERO + tempMinute : Integer.toString(tempMinute);
    }
}

Related

  1. isValidSendDate(Date sendDate)
  2. isWorkingDay(final Calendar calendar, final Long[] holidays)
  3. postponeWorkingDay(final Calendar calendar, final int measureUnit, final int amount, final Long[] holidays)
  4. previousWorkingDay(final Calendar calendar, final Long[] holidays)
  5. secondsBetween(Date start, Date end, boolean assumeSameDate, boolean assumeSameHour)
  6. secondsToEndOfDay(Date aDate)
  7. setEndDay(Date date)
  8. setTimeToEndofDay(Calendar calendar)
  9. setTimeToEndOfDay(Date date)