- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想更改 rails (created_at, modified_at) 的魔法列的默认时间戳,而不是 2010-09-03 14:52:46 UTC 我想将其更改为 2010 年 9 月 10 日 02:52下午。或者至少以这种方式解析。
现在,我知道我可以通过操纵变量在 View 中做到这一点,但是没有更“简单的方式”我可以在模型中做到这一点,然后将其作为方法调用吗?
最佳答案
class YourModel < ActiveRecord::Base
def my_formated_date_time
created_at.strftime("%B %d, %Y at %I:%M %p")
end
end
或者您可以使用本地化格式。将此添加到您的 config/locale/your_locale.yml
。恕我直言:这将是最railish 的方式。
your_locale:
time:
formats:
default: "%B %d, %Y at %I:%M %p"
然后在你看来这样做
<%=l @your_model.created_at %>
<!-- short for: -->
<%= I18n.localize @your_model.created_at %>
关于ruby-on-rails - 更改魔法列的时间戳 (Rails),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3637071/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!