set Start Of Month - Java java.util

Java examples for java.util:Month

Description

set Start Of Month

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar = Calendar.getInstance();
        System.out.println(setStartOfMonth(calendar));
    }/*from   w  w  w.java2  s.  com*/

    public static Calendar setStartOfMonth(Calendar calendar) {
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar = setStartOfDate(calendar);
        return calendar;
    }

    public static Calendar setStartOfDate(Calendar calendar) {
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }
}

Related Tutorials