• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Time without date. Help!

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic