Here you can find the source of getNextMonthFistDay(String nowdate, String inFormat, String outFormat)
public static String getNextMonthFistDay(String nowdate, String inFormat, String outFormat) throws ParseException
//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; } }