Java Date Adjust adjustHourAndMinute(Date n)

Here you can find the source of adjustHourAndMinute(Date n)

Description

adjust Hour And Minute

License

Open Source License

Declaration

public static Date adjustHourAndMinute(Date n) 

Method Source Code


//package com.java2s;
/*/*from w  w  w.java2s .co m*/
 * Copyright 2013 GiavaCms.org.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

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

public class Main {
    public static Date adjustHourAndMinute(Date n) {
        if (n == null)
            n = new Date();
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minutes = cal.get(Calendar.MINUTE);
        cal.setTime(n);
        cal.set(Calendar.MINUTE, minutes);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        return cal.getTime();
    }
}

Related

  1. adjustDate(Date dtDate, int iYears, int iMonths, int iDays, int iHours, int iMinutes, int iSeconds)
  2. adjustDays(Date startingDate, int deltaDays)
  3. adjustHour(Date dt, int hour)
  4. adjustTime(Date date, int hour, int minute, int second)
  5. adjustToDayStartAndEnd(Date from, Date to)
  6. getAdjustDayResetTime(Date date, int adjustAmount)
  7. getAdjustedDate(Date original, int millisecondAdjustment)