Parse String in yyyy-MM-dd HH:mm:ss format to Calendar - Android java.util

Android examples for java.util:Calendar Format

Description

Parse String in yyyy-MM-dd HH:mm:ss format to Calendar

Demo Code


//package com.java2s;
import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    static String TAG = "CalendarHandler";

    public static Calendar string2Calendar2(String string) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        Date date = null;/*  www. j  a  va 2  s  . c  om*/
        try {
            date = format.parse(string);
        } catch (ParseException e) {
            Log.e(TAG, "");
        }
        calendar.setTime(date);
        return calendar;
    }
}

Related Tutorials