Difference between DateTime and Time in Ruby

前端 未结 7 1091
眼角桃花
眼角桃花 2020-11-27 10:03

What\'s the difference between DateTime and Time classes in Ruby and what factors would cause me to choose one or the other?

7条回答
  •  迷失自我
    2020-11-27 10:31

    It seems that in some cases the behavior is very different:

    Time.parse("Ends from 28 Jun 2018 12:00 BST").utc.to_s
    

    "2018-06-28 09:00:00 UTC"

    Date.parse("Ends from 28 Jun 2018 12:00 BST").to_time.utc.to_s
    

    "2018-06-27 21:00:00 UTC"

    DateTime.parse("Ends from 28 Jun 2018 12:00 BST").to_time.utc.to_s
    

    "2018-06-28 11:00:00 UTC"

提交回复
热议问题