Reputation: 37
I do a rs.getTimestamp("datetime")
in Java.
In the database, this datetime is 2009/03/06 02:47:18
but the time is returned as 14:47:18
I'm not very knowledgeable about MySQL dates, so I would appreciate any explanation as to why this is happening.
Upvotes: 0
Views: 453
Reputation: 37
SimpleDateFormat time = new SimpleDateFormat("HHmmss");
datime = time.format(rs.getTimestamp("datetime"))
and then datime is printed to a file.
the datetime column in the table is a datetime Data Type
Upvotes: 0
Reputation: 39907
It doesn't matter. Its not about MySQL or any database. This is the format Timestamp shows up by default, I believe. It doesn't mean it missed the date or something.
You can always format the Timestamp returned by the method in any format in your code. Check out java.text.SimpleDateFormat class. Or for better, check out much more sophisticated Joda Time.
Upvotes: 2
Reputation: 4682
Two things. First, I think we need sample code. What's going on is not at all clear from what you've given us. Context, usage, DB schema, and sample rows as well.
Second, ResultSet.getTimestamp() should be returning an object of type Timestamp, rather than a String of any sort.
Upvotes: 1