4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UTCをJSTにする方法

Posted at

Excel

2018-02-27 15:03:48.000000 UTC

という文字列がA1に入ってるとしたらこう。

=DATEVALUE(MID(A1,1,10))+TIMEVALUE(MID(A1,12,8))+TIME(9,0,0)

Rails

ほんとはJSTだったのにUTCのタイムゾーンがついてしまってる日時をタイムゾーンだけ変更するならこう(実行環境がJSTの前提)

d = Time.parse('2018-03-06 11:00:00 +00:00')
Time.zone.local_to_utc(d).in_time_zone #=> Tue, 06 Mar 2018 11:00:00 JST +09:00

UTCだと思ってたのは錯覚で、実はJSTだったというときも大丈夫。

d = Time.parse('2018-03-06 11:00:00 +09:00')
Time.zone.local_to_utc(d).in_time_zone #=> Tue, 06 Mar 2018 11:00:00 JST +09:00
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?