convert String To Calendar - Android java.util

Android examples for java.util:Date Convert

Description

convert String To Calendar

Demo Code

import android.content.Context;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//from ww w  .j a v a 2 s.  c om
     * Convert string to calendar
     * 
     * @param time
     * @return
     */
    public static Calendar convertStringToCalendar(String time,
            String format) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateformat = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = dateformat.parse(time);
            calendar.setTime(date);
            return calendar;
        } catch (ParseException e) {
            return calendar;
        }
    }

}

Related Tutorials