Skip to content

Instantly share code, notes, and snippets.

@kalv
Created December 11, 2012 19:12
Show Gist options
  • Save kalv/4261166 to your computer and use it in GitHub Desktop.
Save kalv/4261166 to your computer and use it in GitHub Desktop.
What is going on here?
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
$ ruby test_time.rb
Parsing the timestamp 2012-12-11 18:01:54.246524000
The float compare to string formatted output: false
"1355277714.2465239"
"1355277714.246524"
require 'rubygems'
require 'time'
require 'active_support'
timestamp_to_parse = "2012-12-11 18:01:54.246524000"
puts "Parsing the timestamp #{timestamp_to_parse}"
time = Time.parse(timestamp_to_parse)
puts "The float compare to string formatted output: #{time.to_f.to_s == time.strftime("%s.%6N")}"
p time.to_f.to_s
p time.strftime("%s.%6N")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment