Java Calendar to String dateToCalendar(final String date)

Here you can find the source of dateToCalendar(final String date)

Description

date To Calendar

License

GNU General Public License

Parameter

Parameter Description
date Expects 'yyyy-MM-dd'

Exception

Parameter Description
ParseException an exception

Declaration

public static Calendar dateToCalendar(final String date) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static String DATE_FORMAT = "yyyy-MM-dd";

    /**/* ww  w.  jav  a 2s .  co m*/
     *
     * @param date Expects 'yyyy-MM-dd'
     * @return
     * @throws ParseException
     */
    public static Calendar dateToCalendar(final String date) {

        // Protection
        assert date != null : "'date' can't be null";
        assert date.length() != 0 : "'date' can't be empty";

        Calendar cal = Calendar.getInstance();

        try {
            cal.setTime((Date) new SimpleDateFormat(DATE_FORMAT).parse(date));
        } catch (ParseException e) {
            // If failed return a so called null object. Uninitialised.
        }

        return cal;
    }
}

Related

  1. calendarToString(Calendar calendar)
  2. calendarToString(Calendar calendar, String template)
  3. calendarToString(Calendar date, boolean transformToLocalTime)
  4. CalendarToString(Calendar fecha, String formato)
  5. calendarToXSDString(Calendar cal, String fmt)
  6. dateToString(Calendar date, DateFormat format)
  7. getDateString(Calendar cal)
  8. getDateString(Calendar cal)
  9. getDateString(Calendar calendar)