Java Day Of Year getDayFromYear(String year)

Here you can find the source of getDayFromYear(String year)

Description

get Day From Year

License

Open Source License

Declaration

public static int getDayFromYear(String year) 

Method Source Code

//package com.java2s;
/*//  w w  w  . j a  v a2  s. com
 * Copyright 2012-2014 sammyun.com.cn. All rights reserved.
 * Support: http://www.sammyun.com.cn
 * License: http://www.sammyun.com.cn/license
 */

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

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    private static String year_format = "yyyy";

    public static int getDayFromYear(String year) {
        SimpleDateFormat format = new SimpleDateFormat(year_format);
        Date date;
        int day = 0;
        try {
            date = format.parse(year);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            day = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }
}

Related

  1. daysInPriorYears(final int y)
  2. daysInPriorYears(int yr)
  3. daysInPriorYears(int yr, boolean use1904windowing)
  4. daysInYear(int yearInteger)
  5. firstdayofyear()
  6. getDaysInYear(final int year)
  7. getDaysInYear(int year)
  8. getDaysInYear(int year)
  9. getDaysOfYear(int year)