Java Year Month getDate(int year, int month, int day, int hour, int minute)

Here you can find the source of getDate(int year, int month, int day, int hour, int minute)

Description

get Date

License

Open Source License

Declaration

public static final Date getDate(int year, int month, int day, int hour, int minute) 

Method Source Code


//package com.java2s;
/*//  w ww  .j av  a2 s .  c  o  m
 * Copyright 2007 Sun Microsystems, Inc.
 * All rights reserved.  You may not modify, use,
 * reproduce, or distribute this software except in
 * compliance with  the terms of the License at:
 * http://developer.sun.com/berkeley_license.html
 */

import java.util.*;

public class Main {
    public static final Date getDate(int year, int month, int day, int hour, int minute) {
        // returns a Date with the specified time elements
        Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month), day, hour, minute);

        return cal.getTime();
    }

    public static final Date getDate(int year, int month, int day) {
        // returns a Date with the specified time elements,
        // with the hour and minutes both set to 0 (midnight)
        Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month), day);

        return cal.getTime();
    }

    private static int intToCalendarMonth(int month) {
        if (month == 1) {
            return Calendar.JANUARY;
        } else if (month == 2) {
            return Calendar.FEBRUARY;
        } else if (month == 3) {
            return Calendar.MARCH;
        } else if (month == 4) {
            return Calendar.APRIL;
        } else if (month == 5) {
            return Calendar.MAY;
        } else if (month == 6) {
            return Calendar.JUNE;
        } else if (month == 7) {
            return Calendar.JULY;
        } else if (month == 8) {
            return Calendar.AUGUST;
        } else if (month == 9) {
            return Calendar.SEPTEMBER;
        } else if (month == 10) {
            return Calendar.OCTOBER;
        } else if (month == 11) {
            return Calendar.NOVEMBER;
        } else if (month == 12) {
            return Calendar.DECEMBER;
        } else {
            return Calendar.JANUARY;
        }
    }
}

Related

  1. getAllDate(String year_month)
  2. getBeginEndDayOfMonth(String yearMonthString)
  3. getCurrentYearMonthDay()
  4. getCurYearMonth()
  5. getDate(int year, int month, int day)
  6. getDaysOfMonth(String year, String month)
  7. getEndDateOfMonth(int year, int month)
  8. getFirstDay(String yearMonthStr, int range)
  9. getFirstDayByMonthWeek(int year, int month, int week)