• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hours and minutes set/get sql timestamp

 
Lou Caudell
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in need of providing a page to permit the manipulation of hours and minutes in a sql timestamp. The user will be able to set the hour and minute for an event. Of course I could parse out string values, but I want the correct class structure, so that a call to get/set the hour and minute values are possible. Anyone have thoughts on the class structure to use here.
<class type> <instName> = rs.getTimestamp(1);
 
Lou Caudell
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should add, taglibs are not an option at this time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not something you should really be doing in a JSP. Pass the user input, which will be strings (no way aorund that) to a class that employs java.util.Calendar to set and get the individual field values.
 
Lou Caudell
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I do have an mvc2 architecture. So if I understand your suggestion, the calendar class should be instantiated from the timestamp value?. Can you give an example?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't really, since I'm not understanding exactly what you are doing. But, if you want to set and get particular fields from a date value, Calendar allows you to do that. When setting the timestamp into the Calendar you are likely to lose the nano values so if that level of precision is important to you, it may not be viable.
 
Lou Caudell
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have worked out the reading of the timestamp with a timeDate class that instantiates calendar. But I am still struggling with how to set the new hour, minute values back into a timestamp since timestamp( yy:mm:dd hh:mm:ss.sss ) has been deprecated.
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the constructor that takes a long as the argument:

new java.sql.Timestamp(calendar.getTime().getTime())


Question - What are you trying to specify? an exact moment in time or a time of day to occur every day?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic