开发者

Time.now in activerecord format

开发者 https://www.devze.com 2023-01-10 16:33 出处:网络
I need it for an unit test... how to get a time.n开发者_高级运维ow in the same format as active record returns for a datetime field?Time.now.strftime(\"%Y-%m-%d %H:%M:%S\")

I need it for an unit test... how to get a time.n开发者_高级运维ow in the same format as active record returns for a datetime field?


Time.now.strftime("%Y-%m-%d %H:%M:%S")


The UTC is probably added by Rails itself. Have you checked at your database console how exactly is stored the date?

Anyway, a shorter way to do the above is Time.now.to_s(:db), but what you're probably looking for is Time.now.to_formatted_s :rfc822 (Documentation here)

0

精彩评论

暂无评论...
验证码 换一张
取 消