Java Time Format getEndDate(String time, SimpleDateFormat dateFormat)

Here you can find the source of getEndDate(String time, SimpleDateFormat dateFormat)

Description

get End Date

License

Open Source License

Declaration

public static String getEndDate(String time, SimpleDateFormat dateFormat) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

public class Main {

    public static String getEndDate(String time, SimpleDateFormat dateFormat) throws ParseException {
        Date nowDate = new Date();
        Date timeDate = stringToDate(time, dateFormat);
        String endDate = "";
        if (timeDate.after(nowDate)) {
            endDate = dateFormat.format(nowDate);
        } else {//from  www  . j  a  v  a  2  s. co  m
            endDate = dateFormat.format(timeDate);
        }
        return endDate;
    }

    public static Date stringToDate(String dateStr, SimpleDateFormat dateFormat) throws ParseException {
        Date date = dateFormat.parse(dateStr);
        return date;
    }

    public static long parse(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static long parse(String date, String pattern) {

        SimpleDateFormat sdft = new SimpleDateFormat(pattern);
        try {
            return sdft.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}

Related

  1. getCurDateTimeFormat(String Format)
  2. getCurrDatetimeWithDbFormat()
  3. getCurTime(String dateformat)
  4. getDefaultDatetimeFormat()
  5. getDefaultPropertyPageDateTimeFormat()
  6. getFormat2TimetagStr()
  7. getFormatDate(Date date, boolean ShowTimePart_in)
  8. getFormatDate(String timeString, String format)
  9. getFormatDatetime()