Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
106 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...