Java Month Format getUpMonthDate(String date, String dateFormat)

Here you can find the source of getUpMonthDate(String date, String dateFormat)

Description

get Up Month Date

License

Open Source License

Declaration

public static Date getUpMonthDate(String date, String dateFormat) 

Method Source Code


//package com.java2s;
/*/*  www  .ja va  2 s.  c  o  m*/
 * Copyright 1998-2012 360buy.com All right reserved. This software is the confidential and proprietary information of
 * 360buy.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with 360buy.com.
 */

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

public class Main {

    public static Date getUpMonthDate(String date, String dateFormat) {
        Calendar c = new GregorianCalendar();
        c.setTime(strToDate(date, dateFormat));
        c.add(Calendar.MONTH, -1);
        return c.getTime();
    }

    public static Date strToDate(String dateStr, String formatStr) {
        Date date = null;
        if (dateStr != null && !"".equals(dateStr)) {
            SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
            try {
                date = sdf.parse(dateStr);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }
}

Related

  1. getDisplayMonth(Date time, int monthBefore, int monthAfter, SimpleDateFormat format)
  2. getFirstDayOfNextMonth(String dateFormat)
  3. getFormatCurMonthAsYYYYMM()
  4. getLastYearMonthYYYYMM()
  5. getMonthFormat(String dateString)
  6. getYesterMonthDate(String format)
  7. monthsBetween(String from, String to, String format)