It doesn't matter. The format(Object)
is part of the base Format
interface; DateFormat
also provides a format(Date)
for clarity.
Ultimately, the format(Object)
version calls DateFormat.format(Object, StringBuffer, FieldPosition)
which, from the source, will attempt the following, in order:
- If object is a
Date
, cast toDate
and perform same conversion asformat(Date)
. - If object is a
Number
, construct anew Date(((Number)object).longValue())
then format that. - Otherwise, throw an
IllegalArgumentException
.
That first point makes format(Object)
identical to format(Date)
when the object is a Date
.
In your case, since date is an Object
, I would simply use format(Object)
because it is less verbose, and format(Object)
will do the cast for you.