13

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;
}
Community
  • 1
  • 1
azriebakri
  • 1,023
  • 2
  • 10
  • 32
  • Please edit your answer to give us the error code it's giving? Cheers and maybe some more relevant code to show how you're using that snippet of code. :) – Imdad Aug 20 '16 at 15:47

2 Answers2

70

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

EpicPandaForce
  • 75,743
  • 26
  • 240
  • 404
3

Change your import

import android.icu.text.SimpleDateFormat;

to

import java.text.SimpleDateFormat;
Farhad
  • 6,158
  • 8
  • 38
  • 63