加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – DateTime类的重点是什么?

发布时间:2020-12-17 02:18:07 所属栏目:百科 来源:网络整理
导读:DateTime类似乎是多余的,在读取该类的Rails扩展的文档中的这一位后,它似乎也有潜在危险: DateTimes aren’t aware of DST rules,so use a consistent non-DST offset when creating a DateTime with an offset in the local zone 还有这个,在DateTime#to_ti
DateTime类似乎是多余的,在读取该类的Rails扩展的文档中的这一位后,它似乎也有潜在危险:

DateTimes aren’t aware of DST rules,so use a consistent non-DST offset when creating a DateTime with an offset in the local zone

还有这个,在DateTime#to_time的Rails文档中:

Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class. If self has an offset other than 0,self will just be returned unaltered,since there’s no clean way to map it to a Time.

我假设最后一部分是由于DateTime没有识别DST.

在我看来,我们有这个:

> Date类表示没有时间的简单日期.
> Time类表示特定时间点,隐含地包含日期.
> DateTime类与Time类相同,但不了解DST,有时无法转换为常规Time类.

那么,DateTime是否应该从代码库中消失,还是它有助于我缺少一个有用的目的?

解决方法

在Rubies中,DateTime在32位机器上具有优于Time的优势. 1.9.2 – 时间是 Y2K38 problem的受害者,限制在32位范围内.在64位计算机和/或最近的Ruby版本中解决了这个问题.您仍然可能需要使用DateTime,例如,1.8兼容性是必须的,或者您依赖于使用其API的方法,这些方法通常与Time的方法不同.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读