Java Day Add addDay(String data)

Here you can find the source of addDay(String data)

Description

add Day

License

Apache License

Declaration

public static String addDay(String data) 

Method Source Code

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

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

public class Main {
    public static String addDay(String data) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cd = Calendar.getInstance();
        try {/* w  w  w  . j a v a  2  s.  c  o m*/
            cd.setTime(sdf.parse(data));
            cd.add(5, 1);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return sdf.format(cd.getTime());
    }

    public static String addDay(int add) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cd = Calendar.getInstance();
        cd.setTime(new Date());
        cd.add(5, add);
        return sdf.format(cd.getTime());
    }

    public static String addDay(String data, int add) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cd = Calendar.getInstance();
        try {
            cd.setTime(sdf.parse(data));
            cd.add(5, add);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return sdf.format(cd.getTime());
    }

    public static String format(Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                DateFormat dateFormat = new SimpleDateFormat(format);
                result = dateFormat.format(date);
            }
        } catch (Exception localException) {
        }
        return result;
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }

    public static String getTime(Date date) {
        return format(date, "HH:mm:ss");
    }
}

Related

  1. addDay(int k)
  2. addDay(java.util.Date date)
  3. addDay(java.util.Date dt, long day)
  4. addDay(String currentdate, int add_day)
  5. addDay(String d)
  6. addDay(String datetime, int day)
  7. addDayInterval(long millis, int dayInterval)
  8. addDays(Date aDate, int days)
  9. addDays(Date baseDate, int amount, boolean endOfDay)