if current time is 1 min or less then 1 min different then remote time
everything is fine, but more then 1 min difference is a problem
any help will be great.
it would be great if i can do this without installing any ruby module
(which have to install )
The time-management functions that are included in Ruby are excellent.
Just do
require 'time'
and then
t=Time::parse(remote_date+' '+remote_time)
You will have a Time object (do ri Time to know more), on which you
can do arithmetic. Basically, if you subtract a time from another, you
will obtain the difference in seconds.
Carlo
···
Subject: Convert date to string
Date: Mon 12 Nov 12 03:04:03AM +0900
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
You will have a Time object (do ri Time to know more), on which you
can do arithmetic. Basically, if you subtract a time from another, you
will obtain the difference in seconds.
Hi
you said, Substract a time from another, yes thats one i want ..
So bellow works perfect
t=Time::parse(remote_date+' '+remote_time)
t1=Time::parse(current_date+' '+current_time)
puts t
puts t1
Simply use `t1 = Time.new', which returns the current system time.
The OP should be aware that parsing a time out of a string value as
we're doing here will, in the absence of any timezone data, assume a
TZ offset of 0 (UTC/GMT).
The OP was using Time.parse from the `Time' library.
Simply use `t1 = Time.new', which returns the current system time.
The OP should be aware that parsing a time out of a string value as
we're doing here will, in the absence of any timezone data, assume a
TZ offset of 0 (UTC/GMT).
[...]
So if you're trying to compare 2 times, make sure they're using the
same TZ offset as well, or your results will be, erm, suspect
Generally, this is a very good point.
But for the considered example, Time.parse returns local time,
since no time zone was specified in the argument, so it should work.
···
Am 12.11.2012 15:45, schrieb Hassan Schroeder:
On Mon, Nov 12, 2012 at 6:23 AM, <sto.mar@web.de> wrote:
Subject: Re: Convert date to string
Date: Tue 13 Nov 12 12:35:55AM +0900
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
OK, that's disturbing. How is it that I can do Time.new without first
requiring 'time' but Time.parse fails??
Plain time handling is included in the default runtime. Time.rb adds
further functionalities:
# When 'time' is required, Time is extended with additional methods for parsing
# and converting Times.
Carlo
···
Subject: Re: Convert date to string
Date: Tue 13 Nov 12 12:57:24AM +0900
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)