Java Year Month todaySubtract(String years, String months)

Here you can find the source of todaySubtract(String years, String months)

Description

today Subtract

License

Open Source License

Declaration

public final static String todaySubtract(String years, String months) 

Method Source Code

//package com.java2s;
/**/*from   ww w  . j a v a  2  s  .c o m*/
 * @copyright Copyright (C) 2014-2015 City of Bloomington, Indiana. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
 * @author W. Sibo <sibow@bloomington.in.gov>
 */

import java.util.*;

public class Main {
    public final static String todaySubtract(String years, String months) {
        Calendar cal = Calendar.getInstance();
        int yy = 0, mm = 0, dd = 0;
        try {
            if (years != null && !years.equals("0")) {
                yy = Integer.parseInt(years);
            }
            if (months != null && !months.equals("0")) {
                mm = Integer.parseInt(months);
            }
            mm = mm + yy * 12; // total months
            cal.add(Calendar.MONTH, -mm);

        } catch (Exception ex) {
            System.err.println(ex);
        }
        mm = cal.get(Calendar.MONTH) + 1;
        dd = cal.get(Calendar.DATE);
        yy = cal.get(Calendar.YEAR);

        return "" + mm + "/" + dd + "/" + yy;

    }
}

Related

  1. normalizeShortDate(String year, String month, String day)
  2. parseMonthAndYearStringOrNull(String dateString)
  3. sameYearAndMonth(Date d1, Date d2)
  4. toDateProgression(int year, int month, int day, String seed, int pedometer)
  5. toDateProgression(int year, int month, int day, String seed, int pedometer)
  6. toYearMonth(String dateString)