get Start Of Month in Milliseconds - Java java.util

Java examples for java.util:Month

Description

get Start Of Month in Milliseconds

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        int year = 2;
        int month = 2;
        System.out.println(getStartOfMonthMs(year, month));
    }//w w w. j  a va  2s  .c om

    public static long getStartOfMonthMs(int year, int month) {
        final Calendar date = Calendar.getInstance();

        date.set(Calendar.YEAR, year);
        date.set(Calendar.MONTH, month);
        date.set(Calendar.DAY_OF_MONTH,
                date.getActualMinimum(Calendar.DAY_OF_MONTH));
        date.set(Calendar.HOUR_OF_DAY,
                date.getActualMinimum(Calendar.HOUR_OF_DAY));
        date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
        date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
        date.set(Calendar.MILLISECOND,
                date.getActualMinimum(Calendar.MILLISECOND));
        return date.getTimeInMillis();
    }
}

Related Tutorials