gpt4 book ai didi

ruby-on-rails - Rails : Date. 解析 vs string.to_date

转载 作者:行者123 更新时间:2023-12-04 06:27:42 24 4
gpt4 key购买 nike

我想知道两者之间是否有任何区别

Date.parse("2018-05-10")


"2018-05-10".to_date

如果一个比另一个更受欢迎,或者它们真的可以互换。

最佳答案

如果您检查代码 here ,您会看到第二种方法实际上只是调用第一种方法,只对空白进行少量检查。

def to_date
::Date.parse(self, false) unless blank?
end

关于 false争论,查阅文档 here :

If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.

关于ruby-on-rails - Rails : Date. 解析 vs string.to_date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com