Difference between SimpleDateFormat.setTimeZone () and Calendar.setTimeZone ()

What is the difference between SimpleDateFormat.setTimeZone () and Calendar.setTimeZone ()?

+4
source share
3 answers

SimpleDateFormat will use the specified time zone during formatting, and Calendar will consider this time zone as the one with the corresponding date / time. The time zone of the calendar will be converted to the SimpleDateFormat time zone when formatting the calendar instance.

+2
source

Both of these methods do the same.

 SimpleDateFormat.setTimeZone(TimeZone zone) 

essentially a method inherited from java.text.DateFormat. When

 DateFormat.setTimeZone(TimeZone zone) 

he will run

  getCalendar().setTimeZone(TimeZone zone) 

which is the same as

 Calendar.setTimeZone(TimeZone zone) 

They both call the same method that sets the time zone.

+2
source

setTimeZone is a method defined in the DateFormat class that internally contains a Calendar object. So he changed the Calender object and set it to TimeZone, where Calendar.setTimeZone set the time zone of the existing calendar ...

Both of these methods are instance methods.

0
source

All Articles