【问题标题】:Convert a string to type timestamp in rails在rails中将字符串转换为类型时间戳
【发布时间】:2012-07-29 08:42:27
【问题描述】:

我有以下字符串2012-7-31 09:38:00.000000,我想在PGadmin 中将其转换为类型时间戳(无时区)。 ruby 中有哪些方法可以完成这项工作?

谢谢

【问题讨论】:

标签: ruby-on-rails ruby timestamp


【解决方案1】:
Time.parse("2012-7-31 09:38:00.000000").to_i

【讨论】:

  • PG::Error: ERROR: column "time_to_display" is of type timestamp without time zone but expression is of type character 在字符 108 处变化 提示:您将需要重写或转换表达式。跨度>
【解决方案2】:

试试

DateTime.parse("2012-7-31 09:38:00.000000")

#output
Tue, 31 Jul 2012 09:38:00 +0000

DateTime.parse("2012-7-31 09:38:00.000000").to_i
#output is timestamp
1343727480 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-22
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多