Java Day of getYYYY_MM_DD(int offsetDays)

Here you can find the source of getYYYY_MM_DD(int offsetDays)

Description

get YYYMDD

License

Apache License

Declaration

public static String getYYYY_MM_DD(int offsetDays) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private final static ThreadLocal<SimpleDateFormat> YYYY_MM_DD_FORMAT = new ThreadLocal<SimpleDateFormat>() {
        @Override/*from www . j a  v  a 2  s . co m*/
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd");
        }

        ;

    };

    public static String getYYYY_MM_DD(int offsetDays) {
        Calendar calendar = Calendar.getInstance();
        if (offsetDays != 0)
            calendar.add(Calendar.DATE, offsetDays);
        Date date = calendar.getTime();
        return formatDD(date);
    }

    /**
     * yyyy-MM-dd
     *
     * @param date
     * @return
     */
    public static String formatDD(Date date) {
        return YYYY_MM_DD_FORMAT.get().format(date);
    }
}

Related

  1. getTwoDay(String sj1, String sj2)
  2. getTwoDay(String sj1, String sj2)
  3. getTwoDay2String(String startDate, String endDate, Format format)
  4. getWorkingDay(Calendar d1, Calendar d2)
  5. getYesday()
  6. isBirthdayPartAvail(String number)
  7. isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL)
  8. isEndOfDay(GregorianCalendar cal1)
  9. isHoliday(Date date, String[] excludes, String[] includes)