If I'm using code like one below to retrieve data from mysql, is there any way to convert, in the same time (inside the loop), the datetime from mysql to shorter format?
Long: Sep 18, 2012 5:24:12 PM --> to short: 18-09-2012 5:24 PM
But that's because in the code you posted, the timestamp values don't have any format at all. A Date, or a Timestamp, is essentially just a number which represents the number of milliseconds since a certain instant of time. So a question about changing the format at that point is misguided. If you want that timestamp to be displayed in a particular format at some time, then you would use a suitable SimpleDateFormat to do that, at the time you're displaying it.
Paul Clapham wrote:But that's because in the code you posted, the timestamp values don't have any format at all. A Date, or a Timestamp, is essentially just a number which represents the number of milliseconds
But in this case, in the mysql table, column type is datetime not timestamp. So here, before is written to object I can see how its formatted. And even then I cannot format it?
I don't know what you're talking about. It may be true that MySQL displays dates in various formats when it's asked to do that. It's also true (as I already said) that in Java, dates don't have a format.
Remember that your question was about Java, not about MySQL. So what MySQL might do is of no consequence. There is no need to format a Java date until you are prepared to display the result of that formatting.
This is most likely how MySQL behaves too -- when you ask to see a date value, it formats it in some way and displays the result. That doesn't mean that the date "is" formatted in that way, only that MySQL formats it that way when you ask to see it.
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening: