Convert a string to a GregorianCalendar

前端 未结 2 1275
南笙
南笙 2020-11-29 11:50

How do a I take an input birthday string such as 02 26 1991 and make it into a Gregorian Calendar?

I tried parsing it first but it keeps giving me an error message s

2条回答
  •  春和景丽
    2020-11-29 12:31

    Use a DateFormat as shown here:

    Example:

    DateFormat dateFormat = new SimpleDateFormat("hh:mm dd/MM/yy");
    dateFormat.setLenient(false);
    Date d = dateFormat.parse("06:23 01/05/06");
    

    Use the parse() method of the SimpleDateFormat class. You can use setLenient(false) to force strict parsing.

提交回复
热议问题