LoginSignup
1
0

More than 5 years have passed since last update.

タイムゾーンを指定しない日時文字列に対するTime.parseとDateTime.parseの挙動の違い

Posted at

結論

'2017-01-31 01:02:03' をパースしたときに何が起きるか。

Time.parseはローカルタイムになる
Date.parseはUTCになる

実例

Time.parse

Time.parse('2017-01-31 01:02:03')
# => 2017-01-31 01:02:03 +0900

DateTime.parse

DateTime.parse('2017-01-31 01:02:03')
# => #<DateTime: 2017-01-31T01:02:03+00:00 ((2457785j,3723s,0n),+0s,2299161j)>
1
0
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
1
0