Java Month monthDiff(String beforeTime, String endTime)

Here you can find the source of monthDiff(String beforeTime, String endTime)

Description

month Diff

License

Open Source License

Declaration

public static int monthDiff(String beforeTime, String endTime) 

Method Source Code

//package com.java2s;

public class Main {
    public static int monthDiff(String beforeTime, String endTime) {
        if (beforeTime == null || endTime == null) {
            return 0;
        }/* w w  w .j  a va2 s .  co  m*/
        int beforeYear, endYear, beforeMonth, endMonth;
        try {
            beforeYear = Integer.parseInt(beforeTime.substring(0, 4));
            endYear = Integer.parseInt(endTime.substring(0, 4));
            beforeMonth = Integer.parseInt(beforeTime.substring(5, 7)) - 1;
            endMonth = Integer.parseInt(endTime.substring(5, 7)) - 1;
            return (endYear - beforeYear) * 12 + (endMonth - beforeMonth);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}

Related

  1. MONTH(int mh)
  2. month2int(String month)
  3. month2second(int month)
  4. month2String(int month)
  5. monthAlphaToNum(String str)
  6. monthFromDateValue(long x)
  7. monthLength(int year, int month)
  8. monthMillis(int year, int monthNum)
  9. monthStringToInteger(String month)