generate Date At Start Of Year - Java java.util

Java examples for java.util:Year

Description

generate Date At Start Of Year

Demo Code


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

public class Main {
    public static Date generateDateAtStartOfYear(int year) {
        Calendar cal = Calendar.getInstance();
        int field = Integer.MIN_VALUE;
        int value = Integer.MIN_VALUE;
        field = Calendar.YEAR;/*from  w w w .  j av a 2s .  co m*/
        value = year;
        cal.set(field, value);
        field = Calendar.MONTH;
        value = Calendar.JANUARY;
        cal.set(field, value);
        field = Calendar.DAY_OF_MONTH;
        value = 1;
        cal.set(field, value);

        return cal.getTime();
    }
}

Related Tutorials