Java Day getDays(String yyyy)

Here you can find the source of getDays(String yyyy)

Description

get Days

License

Open Source License

Declaration

public static String[] getDays(String yyyy) throws Exception 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String[] getDays(String yyyy) throws Exception {

        StringBuilder sb = new StringBuilder();
        long starttime = stringToTime("yyyyMMdd", yyyy + "0101").getTime();
        long lasttime = stringToTime("yyyyMMdd", yyyy + "1231").getTime();
        for (; starttime <= lasttime; starttime += 1000 * 3600 * 24) {
            sb.append(timeToString("yyyyMMdd", new Date(starttime)));
            sb.append(':');
        }/*from   w ww .j  a  va 2 s  .co m*/
        return sb.toString().split(":");
    }

    public static Date stringToTime(String format, String sDate) throws Exception {
        DateFormat df = new SimpleDateFormat(format);
        Date _date = df.parse(sDate);
        if (timeToString(format, _date).equals(sDate)) {
            return _date;
        } else {
            throw new Exception(sDate + " is error");
        }
    }

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

Related

  1. getDayofTheDate(Date d1)
  2. getDAYOFWEEK(String strDate)
  3. getDayRange(String bday, String eday)
  4. getDays(Date day, int preDays, String format)
  5. getDays(Date sd, Date ed)
  6. getDaysAgo(int interval)
  7. getDaysByYearMonth(String ym)
  8. getDaysForDate(String date)
  9. getDaysforYear()