-2

I want to know whether new Date().toString or Calendar.getInstance().getTime().toString which is better since both give the same output and why choose one over the other?

Scenario: I'm using them just to print time in logs so many in a Class many times I would use them

krrish0690
  • 51
  • 2
  • 11

1 Answers1

0

The Date class tends to be more simple than the Calendar class, but the Calendar class provides localization for you.

I would say that Calendar is probably the better option for you. The Date class is a mutable object meaning it can change after it's constructed. The Calendar class also provides more functionality that the date class does not have.

It can be argued that both the Date class and the Calendar class are broken in there own ways. Ideally you would probably want to use a different library altogether such as the Joda Time library.

gluestick
  • 58
  • 1
  • 5