Java Calendar to Date getDate(Calendar cal)

Here you can find the source of getDate(Calendar cal)

Description

Returns the current time from a calendar object

License

Open Source License

Parameter

Parameter Description
cal Description of the Parameter

Return

The date value

Declaration

public static java.util.Date getDate(Calendar cal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**/*w w  w. j  a va 2 s  . com*/
     *  Returns the current time from a calendar object
     *
     * @param  cal  Description of the Parameter
     * @return      The date value
     */
    public static java.util.Date getDate(Calendar cal) {
        java.util.Date convertedDate = null;
        try {
            SimpleDateFormat formatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT);
            formatter.applyPattern("M/d/yyyy");
            String tmpDate = (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH) + "/"
                    + cal.get(Calendar.YEAR);
            convertedDate = formatter.parse(tmpDate);
        } catch (Exception e) {
            System.err.println("EXCEPTION: DateUtils -> Timestamp ");
        }
        return convertedDate;
    }
}

Related

  1. calendarToDate(Calendar c)
  2. calendarToDate(Calendar cal)
  3. calendarToDateId(Calendar cal)
  4. toDate(Calendar cal)
  5. toDate(Calendar calendar)
  6. toDate(Calendar calender)
  7. toDate(Calendar input)