Java Date Set setDate(Date dateToSet, int hours, int minutes, int seconds, int milisec, TimeZone zone, Locale locale)

Here you can find the source of setDate(Date dateToSet, int hours, int minutes, int seconds, int milisec, TimeZone zone, Locale locale)

Description

Returns a new Date object from the given Date object and sets the given parameters.

License

Apache License

Parameter

Parameter Description
dateToSet the date to set
hours the hours
minutes the minutes
seconds the seconds
milisec the milisec
zone the zone
locale the a locale

Return

the date

Declaration

public static Date setDate(Date dateToSet, int hours, int minutes, int seconds, int milisec, TimeZone zone,
        Locale locale) 

Method Source Code

//package com.java2s;
/**//from   w  w  w.  j av a  2  s  .  co  m
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**
     * Returns a new {@link Date} object from the given Date object and sets the given parameters.
     *
     * @param dateToSet
     *            the date to set
     * @param hours
     *            the hours
     * @param minutes
     *            the minutes
     * @param seconds
     *            the seconds
     * @param milisec
     *            the milisec
     * @param zone
     *            the zone
     * @param locale
     *            the a locale
     * @return the date
     */
    public static Date setDate(Date dateToSet, int hours, int minutes, int seconds, int milisec, TimeZone zone,
            Locale locale) {
        Calendar cal = Calendar.getInstance(zone, locale);
        cal.setTime(dateToSet);
        cal.set(Calendar.HOUR_OF_DAY, hours);
        cal.set(Calendar.MINUTE, minutes);
        cal.set(Calendar.SECOND, seconds);
        cal.set(Calendar.MILLISECOND, milisec);
        return cal.getTime();
    }
}

Related

  1. resetDay(Date date)
  2. resetHourMinSecMill(Date date)
  3. resetTime(Date date)
  4. resetTime(Date dt)
  5. setDate(Date date, int year, int month, int day)
  6. SetDate(int year, int month, int day)
  7. setDate(int year, int month, int day)
  8. setDateHourMinute(Date dateParam, String hourMinute, String format)
  9. setDateSecond(Date dateParam, int second)