Java Date to Minute minuteOf(Date date)

Here you can find the source of minuteOf(Date date)

Description

Dates Extracts the minute of the given Date.

License

Apache License

Parameter

Parameter Description
date the date to extract the minute from - must not be null.

Exception

Parameter Description
NullPointerException if given Date is null

Return

the minute of the given Date

Declaration

public static int minuteOf(Date date) 

Method Source Code

//package com.java2s;
/**//  ww  w  . j  a v  a 2  s .c o  m
 * 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.
 *
 * Copyright 2012-2016 the original author or authors.
 */

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

public class Main {
    /**
     * Dates Extracts the minute of the given Date.
     *
     * @param date the date to extract the minute from - must not be null.
     * @return the minute of the given Date
     * @throws NullPointerException if given Date is null
     */
    public static int minuteOf(Date date) {
        return toCalendar(date).get(Calendar.MINUTE);
    }

    /**
     * Converts the given Date to Calendar, returns null if the given Date is null.
     *
     * @param date the date to convert to a Calendar.
     * @return the Calendar corresponding to the given Date or null if the given Date is null.
     */
    public static Calendar toCalendar(Date date) {
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. getMinutesOfHour(Date dt)
  2. minute(Date date)
  3. minute(final Date date)
  4. minuteAdd(Date date, int val)
  5. minuteDate(Date date, int num)