3

我有一个来自twitter gem的 Tweet 对象,名为@tweet.

我能够做到:

@tweet.created_at --> `@tweet.created_at.class` outputs `Time`

但是,我想更改时区created_at,所以我尝试了:

@tweet.created_at.utc

并得到:

can't modify frozen Time

我将如何从当前的 UTC-08:00 更改created_at为 CET 时间?

4

1 回答 1

4

由于created_at推文的时间字段已被冻结,您无法对其进行修改,因此utc将提高Exception,因为它会尝试更改 的值self。而不是修改外壳来复制变量并重新分配它:

@tweet.created_at = @tweet.created_at.dup.utc
于 2013-12-20T06:55:36.100 回答