f



convert time to ruby time to calculate the time difference.

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/.

0
Ruwan
9/20/2010 3:21:18 PM
comp.lang.ruby 48885 articles. 0 followers. Post Follow

4 Replies
2002 Views

Similar Articles

[PageSpeed] 51

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

0
Francesco
9/20/2010 3:38:42 PM
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/.

0
b.candler (2627)
9/20/2010 5:22:17 PM
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/.

0
abhidsm (3)
3/9/2011 4:37:17 PM
On Wed, Mar 9, 2011 at 9:37 AM, ABHILASH M.A <abhidsm@gmail.com> 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

0
wyhaines (47)
3/9/2011 4:43:14 PM
Reply:

Similar Artilces:

Ruby Time
Hi I am reading the time classes for Ruby. However I can't figure out what time method would be best for sports times. I am referring to this link http://www.ruby.ch/ProgrammingRuby/htmlC/ref_c_time.html I want the times stored to be in a mm:ss:hh format or ss:hh (where hh = hundreths of seconds). The times stored will be of times occuring over distance, and some will be imported from internet sources and some will come from direct user input. I am currently planning to use sequel and sqlite to store and query my data. Any suggestions on the best and most reliable format?...

time.time or time.clock
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower. if time.clock() - time.clock() < time.time() - time.time(): clock = time.clock else: clock = time.time Will this work most of the time, or is there something better? Ron On Jan 14, 7:05 am, Ron Ad...

time.clock() or time.time()
What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to benchmark some function calls for Zope project and when I use t0=time.clock(); foo(); print time.clock()-t0 I get much smaller values than when I use time.clock() (most of them 0.0 but some 0.01) When I use time.time() I get values like 0.0133562088013, 0.00669002532959 etc. To me it looks like time.time() gives a better measure (at least from a statistical practical point of view). peterb...

time.time()
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting 6 so I'm not doing the division right, any tips? On Sat, 24 Jan 2004 13:01:40 -0500, Bart Nessux <bart_nessux@hotmail.com> wrote: >am I doing this wrong: > >print (time.time() / 60) / 60 #time.time has been running for many hours > >if time.time() was (21600/60) then that would equal 360/60 which would >be 6, but I'm not getting 6 so I'm not doing the divisi...

Is time.time() < time.time() always true?
So, I was blazin' some mad chronix, as they say, and got on to thinking about Python. The question was, is the statement: time.time() < time.time() always true? Seems it should be false, since the statement itself occurs at one time instant.. but of course we know that python doesn't execute code that way.. So my question is, why doesn't Python work this way? (PS, I wasn't smoking anything, its a figure of speech :) ) On 21 Nov 2006 15:10:25 -0800, flamesrock <flamesrock@gmail.com> wrote: > So, I was blazin' some mad chronix, as they say, and got on to th...

convert time in and time out
hi all, because I have a list of data that contains Clock_in and Clock_out, how can I know the total hours that have been used where I have converted it to Clock_in at 46200 and Clock_out at 48061 how can I know the total hours that have been used? by the way, did I need to create two new data to merge togather Thanks Not sure what you have or did. If those numbers represent the number of seconds since midnight, and you don't have any in and out combinations that span across midnight, you could use something like: data have; input clock_in clock_out; format x y time.; hours=3D(c...

convert time string in UTC to time in local time
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time = '2007-03-13T15:00:00Z' I want to convert it to my local time. start_time = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M: 00Z')) start_time -= time.timezone This was working fine now, but if I do it for a date next week (such as March 13th in the above example), it breaks because my local time moves to daylight savings time this weekend. So my time is now off by an hour....

RE: Is time.time() < time.time() always true?
Chris Mellon wrote: > On 21 Nov 2006 15:10:25 -0800, flamesrock <flamesrock@gmail.com> > wrote:=20 >> So, I was blazin' some mad chronix, as they say, and got on to >> thinking about Python.=20 >>=20 >> The question was, is the statement: >>=20 >> time.time() < time.time() >>=20 >> always true? Seems it should be false, since the statement itself >> occurs at one time instant.. but of course we know that python >> doesn't execute code that way.. So my question is, why doesn't >> Python work this way?=...

time in milliseconds by calling time.time()
I am trying to measure some system response time by using the time.time () or time.clock() in my script. However, the numbers I get are in 10s of milliseconds. For example, 1248481670.34 #from time.time() 0.08 #from time.clock() That won't work for me, since the response time may be only a few milliseconds. My environment is Solaris 10 with Python 2.4.4 (#7, Feb 9 2007, 22:10:21). SunOS 5.10 Generic_137112-07 i86pc i386 i86pc The tricky thing is, if I run the python interpreter and import the time module, I can get a time floating number in better precision by cal...

Query to return first time and second time, then difference (response time)
I have a table containing records of email traffic, with subject and sent time. I want to create a query which returns the time of the first email in a thread, then the time of the second email in a thread, then the difference in those two times. In other words, response time for each thread. I've done this before, but can't remember how. In words, I did a "min" on date, and then another "min" on date but <> the first min. However, I can't recall exactly how I did that. So, for the first response, I need to find the minimum sent time not equal to the...

i want to know how to calculate settling time , peak time , rise time
hi , hey guys i am doing a project on two area control using fuzzy logic controller , i have done the simulation and obtained the result , i want to calculate the rise time , settling time , peak time from the scope , ive tried the >> stepinfo(filename) command , i am not understanding whether the displayed values are in which units . all i want to do is to calculate the parameters from the graph i obtain from the scope !! parameters like rise time , settling time , peak time from the scope and please let me know in which units i wil be getting them I've tha same p...

Calculating time differences given daylight savings time
I am running Python 2.7 and would like to be able to calculate to the second the time difference between now and some future date/time in the same timezone while taking into account daylight savings time. I do not have pytz. Any ideas how to do it? If it requires having pytz, how would I do it with pytz? Thank you. On Thu, Apr 3, 2014 at 3:45 AM, Washington Ratso <jobhunts02@aol.com> wrote= : > I am running Python 2.7 and would like to be able to calculate to the sec= ond the time difference between now and some future date/time in the same t= imezone while taking into a...

Time calculations utilizing three different time formats
Upfront apology - I am new to usenet groups. I have done extensive due diligence to try to find my answer here, on google, and on http://www.mvps.org/access Regarding netiquette, being new to usenet, I first posted this at http://www.eggheadcafe.com/forumpost.aspx?topicid=3D0&forumpostid=3D1017737= 6 I am not purposefully double posting. I figured this was probably the right place to post. Please forgive any indiscretion. I still need help. This is very lengthy, so to skip the verbose introduction, scroll to "Needed Solution:" Hello to all and thanks to the many Access M...

Calculate the first time, not each time (?)
Hello, I'm doing some engineering which will involve a large number of points -- and I anticipate time problems if all steps are repeated for each one. Here's an outline of the way I'd like to approach it. shapeprimativeXvalues := N[Table[functionpX[v], {v, vlimit}]] shapeprimativeYvalues := N[Table[functionpY[v], {v, vlimit}]] Arriving at these will involve some calculation, and once the results are in, it is unnecessary that the this be repeated when the values are used. adaptshapetoitslocation[v_] := (various operations on or includin...

Re: convert time in and time out
Time values are simply seconds from midnight. If you subtract a time value from another, you get duration in seconds. If you want duration in hours, divide by 3600. -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of peter zeng Sent: Tuesday, October 27, 2009 5:39 PM To: SAS-L@LISTSERV.UGA.EDU Subject: convert time in and time out hi all, because I have a list of data that contains Clock_in and Clock_out, how can I know the total hours that have been used where I have converted it to Clock_in at 46200 and Clock_out at 48061 how can I know the tot...

Subtract MULTIPLE time segments from a single time segment to calculate cycle time
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out time is 2:00PM. The Break times are 1) 9:30 AM to 9:45 AM 2) 11:00AM to 11:30 AM 3) 12:30PM to 12:45 PM Now, suppose an operator starts working on a fresh batch of parts @ 7:00AM MONDAY morning and finishes the batch @ 7:00AM TUESDAY Morning, I need to get answer something like this: 24 hrs(7:00AM Mon - 7:00AM Tue) MINUS 15 Minutes(9:30 AM - 9:45 AM) MINUS 30 Minutes(11:00AM - 11:30 AM) MINUS 15 Minutes...

delta time = time stop
I'm using Python to parse a bunch of s/w test files and make csv files for later report generation by MS ACCESS....(my boss loves the quick turn-around compared to C). Each log file may contain one or more 'sessions', and each session may contain one or more 'nodes'. Each session in the log has an ASCII start and stop time, as does each node. I have the basic parse part done for parameters, errors, etc., but noticed my routine for determining how long each session/node took (delta time) was a bit repetitive, so decided to make a 'stand-alone' routine to handle th...

How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps?
Hi, &nbsp; I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data: &nbsp; Time Stamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&...

Labview time stamp's current time and time of the regional settings differs but i want this to be same.
Hi All, I am changing my time zone to GMT+01:00 (Amsterdan, Berlin etc.,), so systems time&nbsp;changes to italian time. but when i use the labview's time stamp control and select the option of set to current time, the value in the control changes to indian time only(local time). I want this to appear corresponding to the time zone which has been set. &nbsp; if anyone has come across this kind of issues and have the idea, please tell me. &nbsp; Thanks in advance. &nbsp; Regards, sathish. Hi, Thanks for the reply. I got it to work in the same way. &nbsp; bye &nbsp; ...

How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps? #5
Hi, &nbsp; I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data: &nbsp; Time Stamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&...

How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps? #8
Hi, &nbsp; I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data: &nbsp; Time Stamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&...

Getting access to run time of a process from Ruby, as opposed to wall clock time
The C runtime for POSIX includes a clock() function that gives you the amount of time that your process has actually had on the CPU. I've googled for a way to get access to this from Ruby, and all I get is the fact that rubyprof uses this in its implementation. Is there a way to get at this or something equivalent from Ruby without having to write a C extension? Thanks. theosib@gmail.com wrote: > The C runtime for POSIX includes a clock() function that gives you the > amount of time that your process has actually had on the CPU. I've > googled for a way to get access to ...

How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps? #7
Hi, &nbsp; I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data: &nbsp; Time Stamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&...

How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps? #6
Hi, &nbsp; I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data: &nbsp; Time Stamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&...

Web resources about - convert time to ruby time to calculate the time difference. - comp.lang.ruby

Difference - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

3Q EARNINGS: Mark Zuckerberg on the Differences Between Messenger and WhatsApp
When Facebook announced its intent to acquire cross-platform messaging application WhatsApp in February, questions surfaced on whether WhatsApp ...

Facebook Tips: What’s the Difference between Top News and Most Recent?
The following is part of our series, Facebook Tips, which answers some of the most commonly asked questions about using Facebook. While we hope ...

Sky rail: can we tell the difference between petitions and parody any more?
Residential campaigns in Melbourne are frequently beyond parody, so how can we tell when a petition is serious or satire? It's not easy these ...

The "time gap" between men and women — the difference in the amount of time spent on unpaid work.
I'm reading a NYT "Gender Gap" article titled "How Society Pays When Women’s Work Is Unpaid." Men spend more time working for money. Women do ...

The difference between Nordstrom and Home Depot in one chart
... are susceptible to an increase in online shopping habits , why is Home Depot doing so much better? A chart from Stifel highlights the difference ...

Oil deal 'makes no difference': IEA
An IEA official said that a deal between OPEC nations and Russia will 'make no difference' to oil market fundamentals.

How Small Shifts Make a Big Difference
... is essential to good forecasting. This breathtaking video is a good example of how small shifts in viewpoint and time lapses make a big difference ...

Aurilia: Osich, Strickland could make 'huge difference' in Giants' bullpen
... Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Aurilia: Osich, Strickland could make 'huge difference' ...

Sanders Campaign Bungles Difference Between ‘Nouns’ And ‘Adjectives’
'Greed' and 'Fraud' are some of the 'adjectives' that describe Wall Street

Resources last updated: 2/24/2016 11:17:57 PM