Java SQL Date Get getDateEnd(Date date)

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

Description

get Date End

License

Apache License

Declaration

public static Date getDateEnd(Date date) 

Method Source Code


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

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

import java.util.Date;

public class Main {
    public static final String TIME_PATTERN_DEFAULT = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_PATTERN_DEFAULT = "yyyy-MM-dd";

    public static Date getDateEnd(Date date) {
        String dateStr = parseDate2(date, "yyyy-MM-dd");
        dateStr = dateStr + " 23:59:59";
        return parseDateTime(dateStr);
    }//w  w w .  java  2s. c  o m

    public static String parseDate2(Date date, String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        return df.format(date);
    }

    /**
     * Parse a strign and return a datetime value
     * 
     * @param dateValue
     * @return format(yyyy-MM-dd HH:mm:ss)
     */
    public static Date parseDateTime(String dateValue) {
        return parseDate(TIME_PATTERN_DEFAULT, dateValue);
    }

    public static String format(Date aTs_Datetime) {
        return format(aTs_Datetime, DATE_PATTERN_DEFAULT);
    }

    public static String format(Date aTs_Datetime, String as_Pattern) {
        if (aTs_Datetime == null || as_Pattern == null)
            return null;
        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Pattern);

        return dateFromat.format(aTs_Datetime);
    }

    /**
     * @param aTs_Datetime
     * @param as_Pattern
     * @return
     */
    public static String format(Timestamp aTs_Datetime, String as_Pattern) {
        if (aTs_Datetime == null || as_Pattern == null)
            return null;
        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Pattern);

        return dateFromat.format(aTs_Datetime);
    }

    /**
     * Parse a string and return a date value
     * 
     * @param dateValue
     * @return
     * @throws Exception
     */
    public static Date parseDate(String dateValue) {
        return parseDate(DATE_PATTERN_DEFAULT, dateValue);
    }

    /**
     * Parse a string and return the date value in the specified format
     * 
     * @param strFormat
     * @param dateValue
     * @return
     * @throws ParseException
     * @throws Exception
     */
    public static Date parseDate(String strFormat, String dateValue) {
        if (dateValue == null)
            return null;

        if (strFormat == null)
            strFormat = TIME_PATTERN_DEFAULT;

        SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat);
        Date newDate = null;

        try {
            newDate = dateFormat.parse(dateValue);
        } catch (ParseException pe) {
            newDate = null;
        }
        return newDate;
    }

    public static Date parseDate(Date date, String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        String dateStr = df.format(date);
        return parseDate(pattern, dateStr);
    }
}

Related

  1. getDateBefore(Date date, Integer before)
  2. getDateBeforTwelveMonth()
  3. getDateByNum(String dateNum)
  4. getDateByYearAndMonth(int year, int month)
  5. getDateDiscrepancy(String startDate, String endDate)
  6. getDateForStr(String str)
  7. getDateFromISODateString(String isoDate)
  8. getDateFromLong(ResultSet resultSet, int index)
  9. getDateFromResultSet(ResultSet rset, Enum field)