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;
}
2.2.Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally. So SimpleDateFormat instances are not thread-safe, and we should use them carefully in concurrent environments.
Deprecated. A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API.
No, the SimpleDateFormat class is not thread-safe. If you want to share an instance of it between threads, you must synchronize access within each thread. A better alternative is the DateTimeFormatter class. It was introduced in Java 8.
The java SimpleDateFormat allows construction of arbitrary non-localized formats. The java DateFormat allows construction of three localized formats each for dates and times, via its factory methods.
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
It's because you imported android.icu.text.SimpleDateFormat instead of java.text.SimpleDateFormat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With