• 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

DATE/TIME

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...

need some idea or sample codes on this issue

fromActivityDate/Time : 2009-03-13 08:07:00.0
toActivityDate/Time : 2009-03-14 12:33:00.0

from this Date/Time.. how can i fine the total minute from the From and to Date/Time? at least give me the logic how it work...

i been "googeling" over the net..i cant find something similar ...

i know it sound easy but i dont have the idea how can i do..hope sumone able to help me with this

thanks in advance

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Logic:

Convert date into milliseconds
Subtract them
Convert milliseconds to minutes
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are inbuilt classes that can convert a string to a date, you have to specify the format

use this to convert both values into objects and once you have your two date objects, use Sagar Rohankar's method

 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any sample code as a guidance for me? it really help me a lot if i can have some samples codes...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't much code to it if you follow the steps Sagar lists. Do you have the dates/times as Date objects or in some other formats?

Some generic date-handling code is in the http://faq.javaranch.com/java/JavaDatesFaq
 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i have this sample..how can i set the date to what i want?
i think think code is the solution to my problem right?
 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the format

fromActivityDate/Time : 2009-03-13 08:07:00.0
toActivityDate/Time : 2009-03-14 12:33:00.0

 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've solve the first part...
now just left with Convert milliseconds to minutes.. thanks so much all of you man!...
i will just Google and see how to Convert milliseconds to minutes...

thanks so much..

code ranch rock!
 
Sheriff
Posts: 22781
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
Divide by 1000 to get seconds, then by 60 to get minutes comes to mind.

Or, when using Java 6, use java.util.concurrent.TimeUnit:
 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks bob your solution works..but im a bit confuse and doubt where my code goes wrong.
i try your first solution


the result is 0

why is it so..but the i used
it works well as it give me the value...

it just that i cast it to String as i want my return type to be Sting..or i have to ght the value first then only i can turn to String it is?

anyway..the problem solve..thanks so much...
 
Rob Spoor
Sheriff
Posts: 22781
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
What's the value of secondTry? Perhaps elapsed_time / 60000 is a multiple of 60? Because TimeUnit.MILLISECONDS.toMinutes actually just divides by 60000.
 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
4320...it is the right output as the total days is 3days...

its ok..i just the 2nd solution that you gave..it work ..

thanks once again...
 
Rob Spoor
Sheriff
Posts: 22781
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
The first one worked as well, because 4320 % 60 == 0. I would still prefer the second solution though, since it makes it much clearer what you want to do.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic