Java Date Create createDate(int year, int month, int day)

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

Description

create Date

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/**// www  . j av a 2 s .  c  om
 * Copyright (c) 2009 - 2012 Red Hat, Inc.
 *
 * This software is licensed to you under the GNU General Public License,
 * version 2 (GPLv2). There is NO WARRANTY for this software, express or
 * implied, including the implied warranties of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
 * along with this software; if not, see
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
 *
 * Red Hat trademarks are not licensed under GPLv2. No permission is
 * granted to use or replicate Red Hat trademarks that are incorporated
 * in this software or its documentation.
 */

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

public class Main {
    public static Date createDate(int year, int month, int day) {
        Calendar cal = Calendar.getInstance();

        cal.set(Calendar.YEAR, year);
        // Watch out! Java expects month as 0-11
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DATE, day);

        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        Date jsqlD = new Date(cal.getTime().getTime());
        return jsqlD;
    }
}

Related

  1. createDate(int year, int month, int day)
  2. createDate(int year, int month, int day)
  3. createDate(int year, int month, int day)
  4. createDate(int year, int month, int day)
  5. createDate(int year, int month, int day)
  6. createDate(int year, int month, int day, int hour, int minute, int second)
  7. createDate(int year, int month, int day, int hour, int minute, int second, int millisecond)
  8. createDateObject(Integer year, Integer month, Integer dayOfMonth, Integer hourOfDay, Integer minute, Integer second, Integer milissecond)
  9. createDates(int yy, int mm, int dd, int hh, int min, int ss)