Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > convert time to ruby time to calculate the time difference.

Reply
Thread Tools

convert time to ruby time to calculate the time difference.

 
 
Ruwan Budha
Guest
Posts: n/a
 
      09-20-2010
Hi all,

I have following two time stamps,

12:35:10:757 & 12:35:10:759

I want to convert them to ruby time and find the time difference.

which is a 2 micro seconds.

I would appreciate any help..

thanks in advance
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Francesco Vollero
Guest
Posts: n/a
 
      09-20-2010
Il 20/09/10 17.21, Ruwan Budha ha scritto:
> Hi all,
>
> I have following two time stamps,
>
> 12:35:10:757& 12:35:10:759
>
> I want to convert them to ruby time and find the time difference.
>
> which is a 2 micro seconds.
>

Simply:

require 'time'

mT=Time.utc(2010,9,20,12,35,10,757)
=> Mon Sep 20 12:35:10 UTC 2010
mT1=Time.utc(2010,9,20,12,35,10,759)
=> Mon Sep 20 12:35:10 UTC 2010
mT1-mT
=> 2.0e-06

> I would appreciate any help..
>
> thanks in advance
>

You're welcome, but before ask, try to google a bit...[1]


[1] http://ruby-doc.org/core/classes/Time.html#M000252

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      09-20-2010
Alternative:

>> require 'time'

=> true
>> t1 = Time.parse("12:35:10.000757")

=> Mon Sep 20 12:35:10 +0100 2010
>> t2 = Time.parse("12:35:10.000759")

=> Mon Sep 20 12:35:10 +0100 2010
>> t2 - t1

=> 2.0e-06
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
ABHILASH M.A
Guest
Posts: n/a
 
      03-09-2011
Brian Candler wrote in post #942410:
> Alternative:
>
>>> require 'time'

> => true
>>> t1 = Time.parse("12:35:10.000757")

> => Mon Sep 20 12:35:10 +0100 2010
>>> t2 = Time.parse("12:35:10.000759")

> => Mon Sep 20 12:35:10 +0100 2010
>>> t2 - t1

> => 2.0e-06


If you got the ruby time, you can use the gem 'time_diff' to get the
time difference in a useful format like year, month, week, day, hour,
minute, second

https://rubygems.org/gems/time_diff

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Kirk Haines
Guest
Posts: n/a
 
      03-09-2011
On Wed, Mar 9, 2011 at 9:37 AM, ABHILASH M.A <> wrote:
> Brian Candler wrote in post #942410:
>> Alternative:
>>
>>>> require 'time'

>> => true
>>>> t1 = Time.parse("12:35:10.000757")

>> => Mon Sep 20 12:35:10 +0100 2010
>>>> t2 = Time.parse("12:35:10.000759")

>> => Mon Sep 20 12:35:10 +0100 2010
>>>> t2 - t1

>> => 2.0e-06

>
> If you got the ruby time, you can use the gem 'time_diff' to get the
> time difference in a useful format like year, month, week, day, hour,
> minute, second


I haven't looked at the gem, but....it's all just simple math, except
for the month part, which takes a bit more work. Does the gem
_actually_ calculate the difference in months between two dates, or
does it just approximate it?

Kirk Haines
Software Engineer
EngineYard

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculate page execution time =?Utf-8?B?YXNhZA==?= ASP .Net 1 09-26-2005 02:49 PM
how to Calculate Time yoshitha ASP .Net 4 04-19-2005 07:34 PM
How to calculate time for method execution? TomislaW ASP .Net 2 11-10-2004 04:14 PM
Calculate data time Grey ASP .Net 2 09-23-2004 10:09 AM
calculate the download and upload time .. HELP!! Marlon ASP .Net 1 09-10-2004 12:39 PM



Advertisments