Java yyyy formatAddDate(String src, String pattern, int amount)

Here you can find the source of formatAddDate(String src, String pattern, int amount)

Description

format Add Date

License

Apache License

Declaration

public static String formatAddDate(String src, String pattern, int amount) throws ParseException 

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 final SimpleDateFormat date_sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static String formatAddDate(String src, String pattern, int amount) throws ParseException {
        Calendar cal;/* www  .j av  a 2 s .c om*/
        cal = parseCalendar(src, pattern);
        cal.add(Calendar.DATE, amount);
        return formatDate(cal);
    }

    public static Calendar parseCalendar(String src, String pattern) throws ParseException {

        Date date = parseDate(src, pattern);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }

    public static String formatDate() {
        return date_sdf.format(getCalendar().getTime());
    }

    public static String formatDate(Calendar cal) {
        return date_sdf.format(cal.getTime());
    }

    public static String formatDate(Date date) {
        return date_sdf.format(date);
    }

    public static String formatDate(long millis) {
        return date_sdf.format(new Date(millis));
    }

    public static String formatDate(String pattern) {
        return getSDFormat(pattern).format(getCalendar().getTime());
    }

    public static String formatDate(Calendar cal, String pattern) {
        return getSDFormat(pattern).format(cal.getTime());
    }

    public static String formatDate(Date date, String pattern) {
        return getSDFormat(pattern).format(date);
    }

    public static Date parseDate(String src, String pattern) throws ParseException {
        return getSDFormat(pattern).parse(src);

    }

    public static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static Calendar getCalendar(long millis) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(millis));
        return cal;
    }

    private static SimpleDateFormat getSDFormat(String pattern) {
        return new SimpleDateFormat(pattern);
    }
}

Related

  1. format(String dateString)
  2. format(String oldPattern, String newPattern, String data)
  3. format2(Date data)
  4. format6chars(Date date)
  5. format6chars(Date date, TimeZone tz)
  6. formatarData(Date data)
  7. formatarData(String pattern, Date data)
  8. formatarDataArquivo(Date data)
  9. formatAsCassandraDate(Date date)