Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.4k points)
Could someone please advise the current "best practice" around Date and Calendar types.

When writing new code, is it best to always favour Calendar over Date, or are there circumstances where Date is the more appropriate datatype?

1 Answer

0 votes
by (46k points)
The date is a more simplistic class and is essentially there for slow adaptability reasons. If you need to set precise dates or do date arithmetic, try e a Calendar. Calendars also manage localization. The early date manipulation functions of Date have since been opposed.

I manage to use both times in milliseconds as a long (or Long, as relevant) or Calendar when there is a choice.

Both Date and Calendar are uncertain, which tends to perform problems when applying either in an API.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...