Java Day getDayAfter(String dateformat, String day, int filed, int delta)

Here you can find the source of getDayAfter(String dateformat, String day, int filed, int delta)

Description

get Day After

License

Apache License

Declaration

public static String getDayAfter(String dateformat, String day, int filed, int delta) 

Method Source Code


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

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

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

public class Main {
    public static String getDayAfter(String day, int filed, int delta) {
        Calendar c = Calendar.getInstance();

        Date date = null;//from  www  . j  a  v  a 2s .  c  o m

        try {
            date = new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(day);
        } catch (ParseException e) {
        }

        c.setTime(date);

        int iday = c.get(filed);

        c.set(filed, iday + delta);

        String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
        return dayAfter;
    }

    public static String getDayAfter(String dateformat, String day, int filed, int delta) {
        Calendar c = Calendar.getInstance();

        Date date = null;

        try {
            date = new SimpleDateFormat(dateformat).parse(day);
        } catch (ParseException e) {
        }

        c.setTime(date);

        int iday = c.get(filed);

        c.set(filed, iday + delta);

        String dayAfter = new SimpleDateFormat(dateformat).format(c.getTime());
        return dayAfter;
    }

    public static String getDayAfter(Date day, int filed, int delta) {
        return getDayAfter(dateToString(day), filed, delta);
    }

    public static String getDayAfter(String dateformat, Date day, int filed, int delta) {
        return getDayAfter(dateformat, dateToString(day, dateformat), filed, delta);
    }

    public static String dateToString(long date, String formate) {
        return dateToString(new Date(date), formate);
    }

    public static String dateToString(Date date, String formate) {
        if (date == null) {
            return "";
        }
        formate = (formate == null) ? "yyyy-MM-dd HH:mm:ss.SSS" : formate;
        return new SimpleDateFormat(formate).format(date);
    }

    public static String dateToString(Date date) {
        return dateToString(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateToString(long date) {
        return dateToString(new Date(date));
    }
}

Related

  1. getDay(String aDate)
  2. GetDay(String agmipDate)
  3. getDAY(String strDate)
  4. getDay(String string)
  5. getDay(String tempdat, Locale locale)
  6. getDayAfterTommorrowsDateFne()
  7. getDayBefore(Date date)
  8. getDayBegin(Date date)
  9. getDayBetween(String firstDay, String secondDay)