• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DateFormat problem

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In K&B page 465
I ran the program

The output is
d1 = Sun Sep 09 07:16:40 GMT+05:30 2001
9/9/01
parsed = Sun Sep 09 00:00:00 GMT+05:30 2001


K&B says
Notice that because we were using a SHORT style, we lost some precision when we converted the Date to a String. This loss of precision showed up when we converted back to a Date object, and it went from being 7:46 to midnight.

I changes the style to DateFormat.LONG or even MEDIUM,FULL still gets the same output.Still there is a precision loss?
 
David Grindley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev

The problem is that you are calling:



getDateInstance returns a formatter that will only format the date and not the time. So changing the style has no effect on the time part since it is ignored.

Regards

Dave
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
This means that the description in the K&B book is not proper.It is showing the reason as "since the formater is using DateFormat.SHORT so there will be a precision loss."
What should we do in order to format the time also?
[ January 03, 2007: Message edited by: Sanjeev Kumar Singh ]
 
David Grindley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev

I agree with you, it looks like K & B has an error. Anyhow if you want to get a date time format use:


You can find 3 overridden versions of this method in the API documentation.

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic