Java Date Create 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 w  w . j a v  a2  s.co  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.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

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. date(int day, int month, int year)
  2. date(int y, int m, int d)
  3. date(int year, int month, int date)
  4. date(int year, int month, int day)
  5. date(int year, int month, int day)
  6. date(int year, int month, int day)
  7. date(int year, int month, int day, int hour, int minute)
  8. date(int year, int month, int day, int hour, int minute, int second)
  9. longArrayTODateArray(long[] dates_s, SimpleDateFormat dateformat)