Two Laptop Bag*
The moose likes Beginning Java and the fly likes Time without date. Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Time without date. Help!" Watch "Time without date. Help!" New topic
Author

Time without date. Help!

James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
I am writing a servlet which takes a value for a particular time from a database. This time is in the form of msec since epoch. What I want to do is convert this to the time of day for display in an html document. I have managed to return the full date/time value in html (i.e. including day, date, year, timezone), but all I actually want is the time of day, not the day/date/year etc. So, for example, I can create an html document with:
"Sun Jul 02 23:00:00 GMT+01:00 2001"
When all I actually want to display is:
"23:00"
Can anyone help me? Some sample code would be really useful.
Thanks in advance,
James
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Hi, James.
Try something like this:

Running this code returns

but of course, the way I set it up, the specific value you see will depend on when you run it.
For more on java.text.SimpleDateFormat, i.e., what characters you can pass in its constructor's String, click here.
Hope this helps, James.
Art
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Sorry it took me a while to get back to you. That's perfect. I'd resorted to using the getMinutes command, but that's depracated and inefficient. Your way is much better.
Thanks,
James
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Time without date. Help!