get Current Year Begin - Java java.util

Java examples for java.util:Year

Description

get Current Year Begin

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        int year = 2;
        System.out.println(getCurrentYearBegin(year));
    }/*from w w  w .j av  a 2  s .  c o m*/

    public static Date getCurrentYearBegin(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }
}

Related Tutorials