Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby strftime("%Q") broken?

Tags:

ruby

The strftime docs claim that %Q works:

%Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.

But it returns "%Q" for me.

2.1.1 :054 > date = Time.now
 => 2014-06-10 12:28:57 -0700
2.1.1 :055 > date.strftime("%Q")
 => "%Q"

I'm using RVM and Ruby 2.1.1.

Am I doing something wrong, or is this a Ruby bug?

like image 697
k107 Avatar asked Jun 10 '14 19:06

k107


1 Answers

You're declaring a Time object, not a Date or DateTime object. Time's behavior is entirely different from Date or DateTime's.

Try this instead:

require 'date'
Date.today.strftime("%Q")

Hope that helps.

like image 94
Luke Avatar answered Sep 20 '22 03:09

Luke