first Date Of Next Month - Android java.util

Android examples for java.util:Month

Description

first Date Of Next Month

Demo Code


//package com.java2s;

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

public class Main {
    public static Date firstDateOfNextMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);/*from   w w  w. j  ava 2 s.c  o m*/
        calendar.add(Calendar.MONTH, 1);
        Date newDate = calendar.getTime();
        return firstDateOfMonth(newDate);
    }

    public static Date firstDateOfMonth(Date date) {
        try {
            return (new SimpleDateFormat("yyyyMMdd"))
                    .parse((new SimpleDateFormat("yyyyMM")).format(date)
                            + "01");
        } catch (ParseException e) {
            return null;
        }
    }
}

Related Tutorials