from Hyphenated Date String yyyy-MM-dd - Android java.util

Android examples for java.util:Date Format

Description

from Hyphenated Date String yyyy-MM-dd

Demo Code

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 Calendar fromHyphenatedDateString(String hyphenatedDateString) {
    Calendar calendar = Calendar.getInstance();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    try {/*from www .j a v  a2s  .  co m*/
      Date date = sdf.parse(hyphenatedDateString);
      calendar.setTime(date);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return calendar;
  }

}

Related Tutorials