Java Month Add addMonthTimetamp(long lTimeStamp, String _pattern, int month)

Here you can find the source of addMonthTimetamp(long lTimeStamp, String _pattern, int month)

Description

add Month Timetamp

License

Open Source License

Declaration

public static String addMonthTimetamp(long lTimeStamp, String _pattern, int month) 

Method Source Code


//package com.java2s;

import java.util.*;
import java.text.*;

public class Main {
    public static String addMonthTimetamp(long lTimeStamp, String _pattern, int month) {
        Date date = new Date(lTimeStamp);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from www.j  av  a  2  s  .  co  m*/
        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int d = cal.get(Calendar.DATE);

        cal.set(y, m + month, d);

        Date addMonth = cal.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat(_pattern);
        String addMonthStr = formatter.format(addMonth);
        return addMonthStr;
    }

    public static Date getTime(String hhmm) {
        if (hhmm != null && hhmm.length() == 4 && isDigit(hhmm)) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm.substring(0, 2)));
            cal.set(Calendar.MINUTE, Integer.parseInt(hhmm.substring(2, 4)));

            return cal.getTime();
        }

        return null;
    }

    private static boolean isDigit(String digitStr) {
        if (digitStr != null) {
            for (int i = 0; i < digitStr.length(); i++)
                if (!Character.isDigit(digitStr.charAt(i)))
                    return false;
        }
        return true;
    }
}

Related

  1. addMonths(int updateInterval, String dateFormat)
  2. addMonths(java.util.Date today, int monthsToAdd)
  3. addMonths(String s, int month)
  4. addMonths2(String dateStr, int months)
  5. addMonthsAndDays(Date date, int months, int days)
  6. getEndOfMonth(Date currentDate)
  7. getEndOfMonth(Date date)
  8. getEndOfMonth(long date)
  9. monthAdd(final String strDate, final int month)