Java Month of Year getNextMonthFistDay(String nowdate, String inFormat, String outFormat)

Here you can find the source of getNextMonthFistDay(String nowdate, String inFormat, String outFormat)

Description

get Next Month Fist Day

License

Apache License

Declaration

public static String getNextMonthFistDay(String nowdate, String inFormat, String outFormat)
            throws ParseException 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Map<String, SimpleDateFormat> formats = new HashMap();

    public static String getNextMonthFistDay(String nowdate, String inFormat, String outFormat)
            throws ParseException {
        Date date = getDateFromString(nowdate, inFormat);

        Calendar cl = Calendar.getInstance();
        cl.setTime(date);//  w w w .ja  va  2 s .com
        cl.set(2, cl.get(2) + 1);
        cl.set(5, 1);

        date = cl.getTime();
        return getFormatTimeString(date, outFormat);
    }

    public static Date getDateFromString(String date, String pattern) throws ParseException {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.parse(date);
        }
    }

    public static String getFormatTimeString(Date date, String pattern) {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.format(date);
        }
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
        if (sDateFormat == null) {
            sDateFormat = new SimpleDateFormat(pattern);
            formats.put(pattern, sDateFormat);
        }
        return sDateFormat;
    }
}

Related

  1. getNextMonth()
  2. getNextMonth(Calendar aCal)
  3. getNextMonth(Date nowdate, int delay)
  4. getNextMonthFirstDay(String date)
  5. getNextMonthFirstDay(T day)
  6. getNextYearMonth(String yearMonth)
  7. getNrDaysOfMonth(int month, int year)
  8. getNumberOfDays(int year, int month)
  9. getOntologyURIBase(String defaultBase, boolean appendYear, boolean appendMonth, boolean appendDay)