SimpleDateFormat gives API Error

Azrie Bakri :

Whenever I use my SimpleDateFormat in android it keep giving me the error call requires API level 24. Which doesn't make sense since I refer to this tutorial which was a couple of years old.

This is the code that giving out the error

SimpleDateFormat formatter = new SimpleDateFormat("EEE,dd MMM,yyyy HH:mm:ss");

I even try but it's still not working

SimpleDateFormat formatter = new SimpleDateFormat("EEE,dd MMM,yyyy HH:mm:ss",Locale.US);

Here is my method where I'm having problem with

public static long getDateInMillis(String srcDate) {

    SimpleDateFormat formatter = new SimpleDateFormat("EEE,dd MMM yyyy HH:mm:ss");

    long dateInMillis = 0;
    try {
        Date date = formatter.parse(srcDate);
        dateInMillis = date.getTime();
        return dateInMillis;
    }

    catch (java.text.ParseException e) {
        e.printStackTrace();
    }

    return 0;
}
EpicPandaForce :

It's because you imported android.icu.text.SimpleDateFormat instead of java.text.SimpleDateFormat.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=453691&siteId=1