ruby-on-rails – 在Rails中使用datetime
发布时间:2020-12-16 19:50:04 所属栏目:百科 来源:网络整理
导读:如何正确地从datetime对象(post.created_at,准确地)提取时间带有/不受TimeZone的影响?如何提取日,月,年值?如何通过自定义模式提取日/月/年(是否可能)? 解决方法 字符串格式的时间: post.created_at.strftime("FORMAT STRING HERE")# Without the influen
如何正确地从datetime对象(post.created_at,准确地)提取时间带有/不受TimeZone的影响?如何提取日,月,年值?如何通过自定义模式提取日/月/年(是否可能)?
解决方法
字符串格式的时间:
post.created_at.strftime("FORMAT STRING HERE") # Without the influence of time-zone: I take it that you want UTC post.created_at.utc.strftime("FORMAT STRING HERE") 链接strftime文档: 获取小时,分和秒值: post.created_at.hour post.created_at.min post.created_at.sec (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |