K
K
Koshkasobaka2021-07-27 11:52:46
Java
Koshkasobaka, 2021-07-27 11:52:46

How to get data from a date (such as day, month, etc.) if the Date.get.. methods are deprecated?

Dates are stored in the database (SQLite) as a String. I want them to be displayed in relation to the present time like today, yesterday, or a full date. To compare the date with the current time, I need to extract data from the date, I try to do this through Calendar, but I get numbers that do not match the date:

SimpleDateFormat format = new SimpleDateFormat("EEEE, d MMMM , yyyy");
      Calendar calendar = new GregorianCalendar();
      calendar.setTime(format.parse(editTime)); // editTime = "вторник, 27 июля , 2021"

System.out.println(calendar.DAY_OF_MONTH); // получаю почему-то 5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-07-27
@Koshkasobaka

Calendar.DAY_OF_MONTH is a constant. It must be passed to the Calendar::get method.
Read the doc . The best way to get a calendar is with the Calendar.getInstance() factory method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question