Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to format java.sql.Timestamp in required format like 'HH:MM:SS PM DD-MM-YY'

 
Shailesh Kumar Saxena
Greenhorn
Posts: 25
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Working with postgresql 9.2 DB,need to store and display last login time for each user on login. I am storing login time as timestamp without zone.On each successful login I am updating the last login value in DB table. For fetching the last login value in my Action class execute method(working with struts 1.3.8) in required format, I am using..

select to_char(lastlogin,'HH:MM:SS PM DD-MM-YY') from userdetails where ......

I used PreparedStatement object, Problem is I am getting the same previous value each time for each person(the time when first time preparedstatement object query was parsed). I think to_char() method get executed once and stored its value for preparedstatement object. But using preparedstatement object is must. I want to store value in java.sql.Timestamp object and use some method of java.sql.Timestamp class to format. I have tried, but no luck. Any help?Any idea? Please let me know.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not retrieve it as a Timestamp and use (Simple)DateFormat to do the formatting in Java? After all, Timestamp extends Date and can therefore be formatted using DateFormat.
 
Shailesh Kumar Saxena
Greenhorn
Posts: 25
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob
I did the same and finally I got the required result. Thank you for reply.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic