Sylar Sylar - 7 months ago 56
Ruby Question

Stripe Charge Date Format

Again, I am new to stripe. I am using Rails and no JS for this section and I want to display the time a charge was made to the customer in my app. In the charge JSON, I see this:

"created": 1461761985,
.

So in my loop, (shortened):

...
<%= c.created.strftime() %>
...



undefined method `strftime' for 1461761985:Fixnum


I thought I could use strftime but getting few errors. Is there a way of converting this time format to
D-M-Y
, in Rails 4?

Answer

That is a unix timestamp if I'm not wrong. Try these out:

DateTime.strptime(c.created.to_s, '%s')
# or
Time.at(c.created).to_datetime