Java Day of Month toDate(final int year, final int month, final int dayOfMonth)

Here you can find the source of toDate(final int year, final int month, final int dayOfMonth)

Description

create Date instance.

License

Apache License

Parameter

Parameter Description
year a parameter
month Month(start with 1)
dayOfMonth a parameter

Declaration

public static Date toDate(final int year, final int month, final int dayOfMonth) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

import java.util.Date;

public class Main {
    /**//from   w ww  .  j a va2 s.co  m
     * create Date instance.
     * @param year
     * @param month Month(start with 1)
     * @param dayOfMonth
     * @return
     */
    public static Date toDate(final int year, final int month, final int dayOfMonth) {

        return toDate(year, month, dayOfMonth, 0, 0, 0);
    }

    /**
     * create Date instance.
     * @param year
     * @param month Month(start with 1)
     * @param dayOfMonth
     * @param hour
     * @param minute
     * @param second
     * @return
     */
    public static Date toDate(final int year, final int month, final int dayOfMonth, final int hour,
            final int minute, final int second) {

        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, dayOfMonth, hour, minute, second);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
}

Related

  1. getWeekOfLastDayOfMonth(Date date)
  2. isGivenDayOfMonth(java.util.Date date, int dayOfMonth)
  3. isSameDayOfMonth(Date dt1, Date dt2)
  4. newDate(int year, int month, int dayOfMonth)
  5. setDayOfMonth(Date d, int date)