Java Calendar to Date toDate(final Calendar calendar)

Here you can find the source of toDate(final Calendar calendar)

Description

Converts a Calendar-object to a Date.

License

Apache License

Parameter

Parameter Description
calendar The calendar to convert.

Return

The date from the calendar.

Declaration

public static Date toDate(final Calendar calendar) 

Method Source Code

//package com.java2s;
/**//from   w w w . j  a  v  a2s  . c  o  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;

public class Main {
    /**
     * Converts a Calendar-object to a Date.
     *
     * @param calendar
     *            The calendar to convert.
     * @return The date from the calendar.
     */
    public static Date toDate(final Calendar calendar) {
        final Date date = calendar.getTime();
        return date;
    }

    /**
     * Converts the given long value to a Date object.
     *
     * @param millis
     *            the millis
     * @return the date
     */
    public static Date toDate(final long millis) {
        return toDate(toCalendar(millis));
    }

    /**
     * Converts a Date to a Calendar-object.
     *
     * @param date
     *            The date to convert.
     * @return The calendar from the date.
     */
    public static Calendar toCalendar(final Date date) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * Converts the given long value to a calendar object.
     *
     * @param millis
     *            the millis
     * @return the calendar
     */
    public static Calendar toCalendar(long millis) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millis);
        return calendar;
    }
}

Related

  1. getDate(Calendar cal)
  2. toDate(Calendar cal)
  3. toDate(Calendar calendar)
  4. toDate(Calendar calender)
  5. toDate(Calendar input)