我将Stripe的结算结束期限保存到数据库,默认情况下保存为Epoch时间戳1441292360
。如何在cancellation_date
列的订阅表中将其保存为YYYY-MM-DD?
订阅模式:
belongs_to :plan
belongs_to :subscription
belongs_to :user
validates_presence_of :plan_id
validates_presence_of :email
def save_with_stripe_payment
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
self.stripe_customer_token = customer.id
self.cancellation_date = customer.subscriptions.first.current_period_end
save!
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating customer: #{e.message}"
errors.add :base, "There was a problem with your credit card."
false
end
答案 0 :(得分:1)
如果您有unix时间,可以通过运行Time
将其转换为ruby Time.at(unix_time_integer)
对象。要转换为日期,您可以运行Time.at(unix_time_integer).to_date
。