【问题标题】:How to retrieve time without the offset number at the end?如何在最后没有偏移量的情况下检索时间?
【发布时间】:2013-07-24 20:28:35
【问题描述】:

Time.now 会产生类似:

2013-07-24 22:23:08 -0700

我想要:

2013-07-24 22:23:08

用于后续进入数据库。一定要简单一些,但我在Time docs 中没有找到。写Time.now.to_s[0..19] 听起来像是糟糕的编程。

【问题讨论】:

    标签: ruby-on-rails ruby time timestamp


    【解决方案1】:

    你可以通过

    Time.now.to_formatted_s(:db)
    

    你可以从here找到不同的to_formatted_s格式

    Time.now.strftime("%F %T")
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多