Here you can find the source of stringToCalendar(final String str, String format, boolean lenient)
Parameter | Description |
---|---|
str | a parameter |
format | a parameter |
lenient | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static final Calendar stringToCalendar(final String str, String format, boolean lenient) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static final String FORMAT_DATE = "dd/MM/yyyy"; /**//from ww w .ja v a2s. c o m * Convert DD/MM/YYYY string to Calendar. * * @param str * @param lenient * @return Calendar * @throws ParseException */ public static final Calendar stringToCalendar(final String str, boolean lenient) throws ParseException { return stringToCalendar(str, FORMAT_DATE, lenient); } /** * Convert string to Calendar. * * @param str * @param format * @param lenient * @return Calendar * @throws ParseException */ public static final Calendar stringToCalendar(final String str, String format, boolean lenient) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.FRANCE); sdf.setLenient(lenient); Date date = sdf.parse(str); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } /** * Convert DD/MM/YYYY string to calendar (lenient is active). * * @param str * @return Calendar * @throws ParseException */ public static final Calendar stringToCalendar(final String str) throws ParseException { return stringToCalendar(str, true); } /** * Convert string to calendar (lenient is active). * * @param str * @param format * @return Calendar * @throws ParseException */ public static final Calendar stringToCalendar(final String str, String format) throws ParseException { return stringToCalendar(str, format, true); } }