Creates a GregorianCalendar from the specified Date . - Java java.util

Java examples for java.util:Calendar

Description

Creates a GregorianCalendar from the specified Date .

Demo Code

/**//from w ww  .  j  a v a  2s.  com
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */
//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Date date = new Date();
        System.out.println(create(date));
    }

    /**
     * Creates a {@link GregorianCalendar} from the specified {@link Date}.
     * @param date the date
     * @return a new GregorianCalendar with the specified value.
     */
    public static GregorianCalendar create(Date date) {
        GregorianCalendar result = new GregorianCalendar();
        result.setTime(date);
        return result;
    }
}

Related Tutorials