Skip to content

Instantly share code, notes, and snippets.

@rahim
Created March 6, 2015 10:15
Show Gist options
  • Save rahim/f657a9dc75f1dc82a772 to your computer and use it in GitHub Desktop.
Save rahim/f657a9dc75f1dc82a772 to your computer and use it in GitHub Desktop.
ISO8601 millisecond handling in Ruby 2.1.5
2.1.5 (main):0 > Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:12.974"
2.1.5 (main):0 > str = Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:26.497"
2.1.5 (main):0 > Time.parse(str)
=> 2015-03-06 10:09:26 +0000
2.1.5 (main):0 > t = Time.parse(str)
=> 2015-03-06 10:09:26 +0000
2.1.5 (main):0 > t.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:26.497"
2.1.5 (main):0 > str = Time.now.strftime('%F %T.%L')
=> "2015-03-06 10:14:05.369"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment