Parse string yyyyMMdd format To Calendar - Android java.util

Android examples for java.util:Calendar Format

Description

Parse string yyyyMMdd format To Calendar

Demo Code


//package com.java2s;

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

public class Main {
    public static Calendar stringToCalendar(String datestring) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        try {//from  w w  w  .  ja  va 2 s . c o m
            Date date = df.parse(datestring);
            calendar.setTime(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return calendar;
    }
}

Related Tutorials