Java Year Get getYearEnd(Date date)

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

Description

get Year End

License

Open Source License

Declaration

public static Date getYearEnd(Date date) 

Method Source Code


//package com.java2s;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date getYearEnd(Date date) {
        String newDateStr = FormatDate(date, "yyyy") + "-12-31";
        return stringToDateShort(newDateStr);
    }/* w w  w. j a  va2  s  .c  o  m*/

    public static String FormatDate(Date date, String sf) {
        if (date == null)
            return "";
        SimpleDateFormat dateformat = new SimpleDateFormat(sf);
        return dateformat.format(date);
    }

    public static Date stringToDateShort(String dateString) {
        String sf = "yyyy-MM-dd";
        Date dt = stringToDate(dateString, sf);
        return dt;
    }

    public static Date stringToDate(String dateString) {
        String sf = "yyyy-MM-dd HH:mm:ss";
        Date dt = stringToDate(dateString, sf);
        return dt;
    }

    public static Date stringToDate(String dateString, String sf) {
        ParsePosition pos = new ParsePosition(0);
        SimpleDateFormat sdf = new SimpleDateFormat(sf);
        Date dt = sdf.parse(dateString, pos);
        return dt;
    }
}

Related

  1. getYear(String strDate)
  2. getYear(String string)
  3. getYear(String tempdat, Locale locale)
  4. getYear(String[] contents)
  5. getYearCount(String from, String to)
  6. getYearForDate(String dateToCheck, String pattern)
  7. getYearList(int years)
  8. getYearLongDesc(Date year)
  9. getYearlyIntervals(Date start, Date end)