Java Day getDayEnd(Date date)

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

Description

get Day End

License

Apache License

Declaration

public static Date getDayEnd(Date date) 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String longFormat = "yyyyMMddHHmmss";

    public static Date getDayEnd(Date date) {
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        df.setLenient(false);/*w w  w.jav  a 2  s . c  om*/

        String dateString = df.format(date);
        dateString += "235959";

        try {
            return parseDateLongFormat(dateString);
        } catch (Exception e) {
            return date;
        }
    }

    public static String format(Date date, String format) {
        if (date == null) {
            return null;
        }

        return new SimpleDateFormat(format).format(date);
    }

    public static Date parseDateLongFormat(String sDate) {
        DateFormat dateFormat = new SimpleDateFormat(longFormat);
        Date d = null;

        if ((sDate != null) && (sDate.length() == longFormat.length())) {
            try {
                d = dateFormat.parse(sDate);
            } catch (ParseException ex) {
                return null;
            }
        }

        return d;
    }
}

Related

  1. getDayBefore(Date date)
  2. getDayBegin(Date date)
  3. getDayBetween(String firstDay, String secondDay)
  4. getDayDate(String date, String formatFormat)
  5. getDayDesc(Date arg)
  6. getDayEndTime(int off, String timezone)
  7. getDayForDate(String dateToCheck, String pattern)
  8. getDayFormat(Date date)
  9. getDayInWeekBeginAndEnd(Date date)