Here "new Date("String")" is constructor is deprecated.if this is cause to produce this result,then explain me how it is?

Thanks Mohan

Joanne Neal

Rancher

Posts: 3742

16

posted 10 years ago

Note that it is the Date constructor that is interpreting the String, not the DateFormat.format() call. The Javadoc says that when interpreting a string of decimal numbers

If the number is followed by a slash, it is regarded as a month ... unless a month has already been recognized, in which case it is regarded as a day of the month.

So the 16 is being recognised as the month. Presumably (although it doesn't say in the Javadoc), if the month is greater than 12, it subtracts 12 from it until it is less than 12 and adds 1 to the year for each subtraction.

Joanne

Chandra Bhatt

Ranch Hand

Posts: 1710

posted 10 years ago

Hi Natarajan,

For sure it is not due to the reason that Date(String arg) constructor has been deprecated.

It is because of the pattern you pass to the SimpleDateFormat(args) constructor. Pattern is really mind boggling for me!