xtravar
xtravar

Reputation: 1351

If Date is mostly deprecated and we're to use Calendar, what is the equivalent of DateFormat class?

I'm new to this Java thing and I'm a little unclear on how I would write my own DateFormat subclass if Date is (mostly?) deprecated.

  1. Should I be using Date or Calendar?
  2. If Calendar across the board, what class replaces DateFormat?

Upvotes: 1

Views: 118

Answers (2)

Aaron Kurtzhals
Aaron Kurtzhals

Reputation: 2036

  1. Date represents a specific millisecond in time. In other words, Date is a wrapper around a long millisecond value. Calendar is used for getting the specific day of the week, month, etc. of a Date.

  2. Use DateFormat. You can use the getDate method of a Calendar to pass a Date object to DateFormat.

Also, you may find Joda time useful.

Upvotes: 1

PermGenError
PermGenError

Reputation: 46408

Firstly java.text.DateFormat class is not deprecated, you use java.util.Date class as a bridge to format a java.util.Calendar object using java.text.DateFormat class.

java.text.DateFormat---> use this class to format dates.
java.util.Calendar  ---> use this class to perform date related operations.

Upvotes: 1

Related Questions