Java Date Set setMinute(Date date, int minute)

Here you can find the source of setMinute(Date date, int minute)

Description

 Set minute of date object. 

License

Open Source License

Parameter

Parameter Description
date target date
minute variable number

Return

Date

Declaration

public static Date setMinute(Date date, int minute) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/* w  w w  .  ja  va2 s .  co m*/
     * <pre>
     * Set minute of date object.
     * 
     *  DateUtils.setMinute(1970-01-01 17:00:00, 17) = 1970-01-01 17:17:00
     * </pre>
     * 
     * @param date target date
     * @param minute variable number
     * @return Date
     */
    public static Date setMinute(Date date, int minute) {
        if (date == null) {
            return null;
        }
        Calendar c = getCalendar(date);
        c.set(Calendar.MINUTE, minute);
        return c.getTime();
    }

    /**
     * get GregorianCalendar.
     * 
     * @return Calendar,GregorianCalendar.
     */
    public static Calendar getCalendar() {
        return new GregorianCalendar();
    }

    /**
     * get GregorianCalendar with given date.
     * 
     * @param date Date.
     * @return Calendar, GregorianCalendar.
     */
    public static Calendar getCalendar(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. setHours(Date d, int hours)
  2. setHours(Date date, int amount)
  3. setMilliSecondsToDate(Date date, Integer milliSeconds)
  4. setMinDate(Date d)
  5. setMinSeconds(Date date)
  6. setMinutes(Date date, int amount)
  7. setStartDateIfNull(java.util.Date start)
  8. setStartDay(Date date)
  9. setStartTime(Date date)