Java Year Day getYearLastDay(String dateString)

Here you can find the source of getYearLastDay(String dateString)

Description

return the last day of the date's year of specified string value in format: yyyy

License

Open Source License

Parameter

Parameter Description
dateString String value

Return

Date value

Declaration

public static Date getYearLastDay(String dateString) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from  ww w  . j a  va 2 s  .  com*/
     * return the last day of the date's year of specified string value in format: yyyy
     *
     * @param dateString
     *       String value
     * @return Date value
     */
    public static Date getYearLastDay(String dateString) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        Date date = null;
        try {
            date = simpleDateFormat.parse(dateString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            calendar.setTime(date);
        }
        calendar.add(Calendar.YEAR, 1);
        calendar.add(Calendar.DATE, -1);
        return calendar.getTime();
    }
}

Related

  1. getLastDayOfYear(int year)
  2. getLastDayOfYear(int year)
  3. getTodayYear()
  4. getWeekNumOfYearDay(String strDate)
  5. getYearFirstDay(String date)
  6. getYearWeek(String curday)
  7. getYearWeek(String curday)
  8. lastDay(Integer year, int month)
  9. lastdayofyear()