time difference calcualtion

D

Daniel Schüle

Hello,

I would like to calculate the difference between two times in seconds
eg

Fri Dec 2 03:12:19 2005
Fri Dec 2 14:44:47 2005

I took a look at Time.singleton_methods but they dont seem apropriate
for this conversion

since I am quite new to Ruby I dont know its libraries or where to search

thx in advance

Regards, Daniel
 
H

Hal Fulton

Daniel said:
=20
I would like to calculate the difference between two times in seconds

require 'time'
t1 =3D Time.parse("Fri Dec 2 03:12:19 2005")
t2 =3D Time.parse("Fri Dec 2 14:44:47 2005")

diff =3D t2 - t1 # diff in seconds



Hal
 
D

dave.burt

Daniel said:
Hello,

I would like to calculate the difference between two times in seconds
eg

Fri Dec 2 03:12:19 2005
Fri Dec 2 14:44:47 2005

I took a look at Time.singleton_methods but they dont seem apropriate
for this conversion

since I am quite new to Ruby I dont know its libraries or where to search

require 'date'
(DateTime.parse("Fri Dec 2 03:12:19 2005") - DateTime.parse("Fri Dec
2 14:44:47 2005")) * 24 * 60 * 60 #=> -41548

Look up the Time, DateTime and Date classes on http://ruby-doc.org/core
for related info.

Cheers,
Dave
 
A

ABHILASH M.A

uval wrote in post #8566:
Hello,

I would like to calculate the difference between two times in seconds
eg

Fri Dec 2 03:12:19 2005
Fri Dec 2 14:44:47 2005

I took a look at Time.singleton_methods but they dont seem apropriate
for this conversion

since I am quite new to Ruby I dont know its libraries or where to
search

thx in advance

Regards, Daniel

Try https://rubygems.org/gems/time_diff/stats

which returns the difference in a hash
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top