用于“2013-03-06"的 Rails 未定义方法“strftime":字符串 [英] Rails undefined method `strftime' for "2013-03-06":String

查看:63
本文介绍了用于“2013-03-06"的 Rails 未定义方法“strftime":字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误

未定义方法`strftime' for "2013-03-06":String

undefined method `strftime' for "2013-03-06":String

尝试使用 strftime 从字符串 2013-03-06 中正常显示日期(2013 年 6 月 3 日或类似日期)时.

when trying to display a date normally (June Sunday 3, 2013 or something similar) from the string 2013-03-06 using strftime.

在我的 index.html.erb 中执行此操作的行看起来像这样

The line that does this in my index.html.erb and looks like this

<%= task.duedate.strftime("%B %e, %Y") %>

我只是在学习 Rails,所以我确定这只是一个愚蠢的初学者错误,任何帮助将不胜感激.谢谢

I am just learning Rails so I am sure it is just a stupid beginners error, any help would be appreciated. Thank you

推荐答案

当 strftime 是 Time/Date 类的方法时,它看起来像是一个字符串.你可以试试这个:

It looks like your duedate is a string, when strftime is a method for Time/Date class. You can try this:

Date.parse(task.duedate).strftime("%B %e, %Y")

这篇关于用于“2013-03-06"的 Rails 未定义方法“strftime":字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆