user710818
user710818

Reputation: 24248

Java why calendar afieldset is false?

I use java calendar. When I change date using calendar.set(...) I see in debugger

areFieldSet=false. 

How can I make it to true? Because when I ask date - I receive not correct value. Thanks.

Upvotes: 0

Views: 322

Answers (3)

unbeli
unbeli

Reputation: 30248

Normally you don't need to care about that. But anyway, calling any method that needs fields to be set, for example calendar.get(0), will make that field true.

Upvotes: 3

Thomas
Thomas

Reputation: 88727

The JavaDoc on that field:

True if fields[] are in sync with the currently set time. If false, then the next attempt to get the value of a field will force a recomputation of all fields from the current value of time.

Since this is an internal field, you shouldn't worry about that.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1502066

Calling an appropriate get method will force the fields to be recomputed - but why do you care? If you just use the public API, you shouldn't care about this field.

As an aside, you might want to look at the Joda Time library as a far superior date/time API for Java.

Upvotes: 2

Related Questions