Java Day End getStartOrEndTime(Date date, int flag)

Here you can find the source of getStartOrEndTime(Date date, int flag)

Description

parameter Date type data and 0 return 2016-08-04 00:00:00 parameter Date type data and 1 2016-08-04 12:59:59

License

Open Source License

Declaration

public static Date getStartOrEndTime(Date date, int flag) 

Method Source Code


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

public class Main {
    /**//  ww  w.  ja v a 2s .co  m
     * parameter Date type data and  0  return  2016-08-04  00:00:00
     * parameter Date type data and  1   2016-08-04  12:59:59
     */
    public static Date getStartOrEndTime(Date date, int flag) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        long millisecond = hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000;
        //start time 00:00:00
        cal.setTimeInMillis(cal.getTimeInMillis() - millisecond);
        if (flag == 0) {
            return cal.getTime();
        } else if (flag == 1) {
            //end  time 23:59:59
            cal.setTimeInMillis(cal.getTimeInMillis() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
        }
        return cal.getTime();
    }
}

Related

  1. getNumYears(Date dStart, Date dEnd)
  2. getSCDEndDate()
  3. getSecondSemesterEndDate(Integer year)
  4. getSendTime(Date sendDate, Date start, Date end)
  5. getStartAndEndDate(Date d)
  6. getSubSeconds(Date minuendDate, Date subDate)
  7. getTimeBeetweenDates(Date d1, Date d2, int timeType)
  8. getTimeInterval(Date startDate, Date endDate)
  9. getTotalDays(Date startDate, Date endDate)