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

Getting the Time Portion of DateTime

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my class that gets remote data I am getting a field as such

2008-08-25 06:58:00.0(incoming date/time)
2008-08-25 17:50:00.0(outgoing date/time)

I will store the time value in an array( in and out). and also the calculated time between both.

How do I get time portion only and also calculate?

Below is for reference only!

I need to show this above data in a table(HTML) as
Gate Activity

Day In Out Calcalted Time
Monday 06:58 17:50 9hours 52minutes
[ August 26, 2008: Message edited by: Steve Dyke ]
 
Ranch Hand
Posts: 83
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are looking for Date Formating, try looking at
SimpleDateFormat and some more classes in java.text package

What is the last zero in your date field...I am not sure about it what it is ...? You may want to separate it with some string manipulation...
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the following code and the time is always 12:00 A :



Will the last .0 cause this. I have no idea how to get rid of it.
[ August 26, 2008: Message edited by: Steve Dyke ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String.indexOf / String.lastIndexOf and String.substring should help you with that.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay the following gets me the two times I need. Now how do I calculate the difference in hours an minutes between them?

 
Sachin Joshi
Ranch Hand
Posts: 83
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I wrote for you....



this should give you difference in miliseconds....you can convert the mili seconds to whatever format you want.

Hope this helps.....
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic