将日期时间转换为月、日和年? [英] Transforming Datetime into month, day and year?

查看:60
本文介绍了将日期时间转换为月、日和年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到这个,我觉得应该很容易.在 Ruby on Rails 中,我该怎么做:

2010-06-14 19:01:00 UTC

把它变成

2010 年 6 月 14 日

我不能只在视图中使用助手吗?

解决方案

我不知道

2010 年 6 月 14 日

但是如果你愿意

2010 年 6 月 14 日

参考 我如何在 ruby​​ on Rails 中获取月份名称?this

就去做

@date = Time.now@date.strftime("%B %d, %Y")

后缀使用如下

@date.strftime("%B #{@date.day.ordinalize}, %Y") # >>>给出`2010 年 6 月 18 日`

I can't seem to find this and I feel like it should be easy. In Ruby on Rails, how do I take:

2010-06-14 19:01:00 UTC

and turn it into

June 14th, 2010

Can I not just use a helper in the view?

解决方案

I don't know for

June 14th, 2010

But if you want

June 14, 2010

Ref how do i get name of the month in ruby on Rails? or this

Just do

@date = Time.now
@date.strftime("%B %d, %Y")

And for suffix use following

@date.strftime("%B #{@date.day.ordinalize}, %Y") # >>> Gives `June 18th, 2010`

这篇关于将日期时间转换为月、日和年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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