• Post Reply Bookmark Topic Watch Topic
  • New Topic

confused on value of date after parsing  RSS feed

 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have alog file that has dates in this format:
Oct 23 11:40:53:426

I use this code to convert the string to date:


When I rollover the logEntryDateTime field, after the above code executes, it shows this value:
Fri Oct 23 11:40:53 MDT 1970

My problem is, I don't understand why it is showing this value.

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rollover the field, as in during a debugging session?
The SimpleDateFormat.parse() will simply attempt to parse a String and create a matching Date object. The String should be formatted identically to the format you specified for the SimpleDateFormat instance, and the resulting Date object is effectively nothing more than a wrapper for a long value that represents the number of milliseconds that have passed since January 1st 1970 GMT. When you "rollover" a Date object in a debugging session it will typically invoke Date's toString() implementation, which is documented as follows:

Converts this Date object to a String of the form:

dow mon dd hh:mm:ss zzz yyyy

So that's why you're seeing what you're seeing

Also, this might be woth a read: A Brief History Of Java Time.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks. I concatenated the current year to the end and it worked a bit better. ;-)

S
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!