Java Date Set setTime(final Date date, final int hourOfDay, final int minute, final int second, final int ms)

Here you can find the source of setTime(final Date date, final int hourOfDay, final int minute, final int second, final int ms)

Description

Set the time of the given Date

License

Open Source License

Parameter

Parameter Description
date a parameter
hourOfDay a parameter
minute a parameter
second a parameter
ms a parameter

Return

new instance of java.util.Date with the time set

Declaration

public static Date setTime(final Date date, final int hourOfDay, final int minute, final int second,
        final int ms) 

Method Source Code

//package com.java2s;
/*/*from   ww  w  .  j ava  2  s  .c  o  m*/
 * Author Stephen Booysen
 *
 * Copyright (c) 2015 Stephen Booysen, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Stephen Booysen. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Stephen Booysen
 *
 * Stephen Booysen MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

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

public class Main {
    /**
     * Set the time of the given Date
     *
     * @param date
     * @param hourOfDay
     * @param minute
     * @param second
     * @param ms
     *
     * @return new instance of java.util.Date with the time set
     */
    public static Date setTime(final Date date, final int hourOfDay, final int minute, final int second,
            final int ms) {
        final GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.HOUR_OF_DAY, hourOfDay);
        gc.set(Calendar.MINUTE, minute);
        gc.set(Calendar.SECOND, second);
        gc.set(Calendar.MILLISECOND, ms);
        return gc.getTime();
    }
}

Related

  1. setStartTime(Date date)
  2. setTime(Date date, int hourOfDay, int minute, int second)
  3. setTime(Date date, int hours, int minutes, int seconds, int millis)
  4. setTime(Date date, String timeString)
  5. setTime(final Date date, final int hourOfDay, final int minute, final int second)
  6. setTime(final Date date, final int hours, final int minutes, final int seconds)
  7. setTimeForDate(Date date, int h, int m, int s)
  8. setTimePart(Date date, String time, Integer milliseconds)
  9. setTimeToNull(Date date)