what does it mean to clear a Calendar variable?

Asked

Viewed 96 times

2

I want to know when I should use clear() and why to use.

SimpleDateFormat simpleDateFormart = new SimpleDateFormat("dd/MM/yyyy");

Date data1 = simpleDateFormart.parse("18/12/1986");
Date data2 = simpleDateFormart.parse("25/01/2017");

Calendar mD = Calendar.getInstance();
Calendar mD2 = Calendar.getInstance();

mD.clear();
mD2.clear();

1 answer

1

The method clear() places all Calendar fields and their value(time value) as "undefined".
This implies that the method isSet() any field returns false.

The "undefined" value is a detail of each implementation, for example Gregoriancalendar uses January 1, 1970 00:00:00.000 GMT(1).

Taking as an example the code that posted, after mD.clear(); mD.YEAR will be 1970.

Source: Class Calendar.

(1) In computation time is counted having as reference this point in time(Epoch/Epoch). Any other point in time is defined in relation to it and represented as the difference in milliseconds between them.

  • Our...I didn’t understand anything...am I too stupid? 1970? Where did this value come from?

  • 1

    See the note I added to the reply. See this also.

  • ok. just a moment I will read. And I come here to talk to you. wait...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.