From: smejmoon@... (G'irts Kalnins) Date: 2004-04-01T22:39:22+09:00 Subject: Re: How to get internal state of DateTime in seconds > >How do you get internal state in seconds of DateTime instance? > >Or convert it to Time instance? > > > >I want to compare two times with variable precision. > >Below is my try to parse time from Common Log Format. > > > >require 'date' > >str1 = '20/Nov/2003:08:08:09 +0200' > >str2 = '20/Nov/2003:08:04:09 +0200' > >fmt='%d/%b/%Y:%H:%M:%S %Z' > >t1 = DateTime.strptime(str1, fmt) > >t2 = DateTime.strptime(str2, fmt) > > > >#what is difference in minutes between these 2 times? > Use to_i if you want it as an integer number of seconds > > $ ruby -we 'puts Time.now.to_i' > => 1080754316 There is no DateTime#to_i Right now I do like below and it looks ugly to me. def dateToTime(str) d = DateTime.strptime(str, fmt='%d/%b/%Y:%H:%M:%S %Z') t = Time.local(d.year, d.month, d.day, d.hour, d.min, d.sec) t end