Here you can find the source of dateToCalendar(final String date)
Parameter | Description |
---|---|
date | Expects 'yyyy-MM-dd' |
Parameter | Description |
---|---|
ParseException | an exception |
public static Calendar dateToCalendar(final String date)
//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; } }