Here you can find the source of createDate(int year, int month, int day)
Parameter | Description |
---|---|
year | Year for the new date |
month | Month of the new date. Should be 1 (Jan) to 12 (Dec) |
day | Day for the new date |
public static Date createDate(int year, int month, int day)
//package com.java2s; /*/*ww w.jav a 2 s . c om*/ * $Id: DateUtils.java,v 1.4 2005/10/10 18:02:45 rbair Exp $ * * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.util.Calendar; import java.util.Date; public class Main { /** * Returns a new date object based on the year, month and day provided. The * date is created using a calender to ensure localization of the date * created. * * @param year Year for the new date * @param month Month of the new date. Should be 1 (Jan) to 12 (Dec) * @param day Day for the new date * @return The new date using */ public static Date createDate(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); synchronized (calendar) { // Java uses a 0 based array for identifying the month. calendar.clear(); calendar.set(year, month - 1, day); return calendar.getTime(); } } }