Java Calendar Parse string2Calendar(String data)

Here you can find the source of string2Calendar(String data)

Description

string Calendar

License

Open Source License

Declaration

public static Calendar string2Calendar(String data) 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    public static Calendar string2Calendar(String data) {

        SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();

        try {/*from  www  . j a  v a  2  s . c o  m*/

            if (data.contains("/"))
                cal.setTime(sdf1.parse(data));
            else
                cal.setTime(sdf2.parse(data));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return cal;
    }
}

Related

  1. convertStringToCalendar(String time)
  2. getCalendar(Object source)
  3. getCalendarObject(String value, boolean hasMills)
  4. str2Calendar(String pString)
  5. str2Calendar(String str, String format)
  6. stringCalendar(Calendar cal)
  7. stringToCalendar(final String str, String format, boolean lenient)
  8. stringToCalendar(String fecha, String formato)
  9. toCalendar(Object value, String format)