• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

datetime conversion

 
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fellows,

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

Cheers,
Thomas
 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.

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.
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
Cheers,
Thomas
 
Paul Clapham
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic