Java Year Month date(int year, int month, int day)

Here you can find the source of date(int year, int month, int day)

Description

Convenience method to create a new date

License

Open Source License

Parameter

Parameter Description
year the year
month the month
day the day

Exception

Parameter Description
IllegalArgumentException if date values are not valid

Return

the date

Declaration

public static Date date(int year, int month, int day) 

Method Source Code

//package com.java2s;
/**// w ww  . j a  va  2 s. c  o  m
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

import java.util.*;

public class Main {
    /**
     * Convenience method to create a new date
     * @param year the year
     * @param month the month
     * @param day the day
     * @return the date
     * @throws IllegalArgumentException if date values are not valid
     */
    public static Date date(int year, int month, int day) {
        return date(year, month, day, 0, 0, 0);
    }

    /**
     * Convenience method to create a new date with time
     * @param year the year
     * @param month the month
     * @param day the day
     * @param hour the hour
     * @param minute the minute
     * @param second the second
     * @return the date
     * @throws IllegalArgumentException if date values are not valid
     */
    public static Date date(int year, int month, int day, int hour, int minute, int second) {
        Calendar cal = new GregorianCalendar(year, month - 1, day, hour, minute, second);
        cal.setLenient(false);
        return cal.getTime();
    }
}

Related

  1. createCalendar(int year, int month, int date, int hour, int minute, int second)
  2. createDate(final int year, final int month, final int day, final int hour, final int minutes, final int seconds, final int miliseconds)
  3. createDate(int year, int month, int day)
  4. createDate(int year, int month, int dayOfMonth)
  5. date(final int year, final int month, final int day, final int hour, final int minute, final int second)
  6. Date2Long(int year, int month, int date)
  7. encodeDateTime(int year, int month, int day, int hour, int minutes, int seconds)
  8. getAddedDate(Date date, int addYear, int addMonth, int addDay, int addHour, int addMinute, int addSecond)
  9. getAllDate(String year_month)