Java Day of getTargetDay(String day, int beforeOrAfterDays)

Here you can find the source of getTargetDay(String day, int beforeOrAfterDays)

Description

get Target Day

License

Apache License

Declaration

public static String getTargetDay(String day, int beforeOrAfterDays) 

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 getTargetDay(String day, int beforeOrAfterDays) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = null;/*from ww  w .j a  v a 2  s .  c  o  m*/
        Date targetDate = null;
        try {
            date = sdf.parse(day);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.DATE, beforeOrAfterDays);
            targetDate = cal.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return sdf.format(targetDate);
    }

    public static String getTime() {
        return getDateTime("HHmmss");
    }

    public static String getDateTime(String format) {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
        String strDate = sdf.format(new java.util.Date());

        return strDate.toString();
    }

    public static String getDateTime() {
        return getDateTime("yyyyMMddHHmmss");
    }
}

Related

  1. getStandardDayFormat(Date day)
  2. getStartDate(int days, String strEndDate)
  3. getStartDateByDays(Date endDate, int days)
  4. getStringAfterNDay(String str, int n)
  5. getStringDay(Calendar cal)
  6. getTheDayBefore(Date date)
  7. getThursday(String date)
  8. getTimeOfDaySeconds()
  9. getTimestamp(String format, Integer daysInFuture)