>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' >t1 = DateTime.strptime(str=str1, fmt='%d/%b/%Y:%H:%M:%S %Z') >t2 = DateTime.strptime(str=str2, fmt='%d/%b/%Y:%H:%M:%S %Z') > >#what is difference in minutes between these 2 times? > >#example with Time instances >t1 = Time.new >t2 = Time.new + 2*60 #2 minutes later > >puts (t1-t2).abs > 60 #diff more than minute Use to_i if you want it as an integer number of seconds $ ruby -we 'puts Time.now.to_i' => 1080754316 /Stefan