Java Day daysOfnumbe(Date sDate, int number)

Here you can find the source of daysOfnumbe(Date sDate, int number)

Description

days Ofnumbe

License

Open Source License

Declaration

public static Date daysOfnumbe(Date sDate, int number) throws ParseException 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;

public class Main {
    public static final String SHORT_TIME_FORMAT = "yyyy-MM-dd";

    public static Date daysOfnumbe(Date sDate, int number) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(SHORT_TIME_FORMAT);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, number);
        return convertStringToDate(SHORT_TIME_FORMAT, sdf.format(c.getTime()));
    }//w w  w  . j  a  v a  2s.c  om

    /**
     * This method generates a string representation of a date/time in the
     * format you specify on input
     * 
     * @param aMask
     *            the date pattern the string is in
     * @param strDate
     *            a string representation of a date
     * @return a converted Date object
     * @throws ParseException
     *             N/A
     * @see java.text.SimpleDateFormat
     */
    public static Date convertStringToDate(String aMask, String strDate) {
        SimpleDateFormat df = new SimpleDateFormat(aMask);
        df.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
        Date date = Calendar.getInstance().getTime();

        try {
            date = df.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return (date);
    }
}

Related

  1. dayFormat(Date date)
  2. dayformMatDate(Date date)
  3. dayOfDate(Date s)
  4. dayOfWeekAbr(Date date)
  5. daysFrom(Date date, int amount, String format)
  6. daySub(Date fDate, Date oDate)
  7. daysWeekName(boolean shortName, Locale locale)
  8. dayToMilliSeconds(String day, String timeZone)
  9. dayToUTCSeconds(String day)