Ruby / Rails - 将日期/时间转换成自然语言(2011-02-17 => 2011年2月17日) [英] Ruby/Rails - Convert Date/Time back into Natural Language (2011-02-17 => February 17th, 2011)
问题描述
我知道慢性,语言转换为数据库计算格式的自然语言解析器,但我想知道如何将数据转换回人类可以轻松理解的东西。
I'm aware of Chronic, the Natural Language Parser for converting language into database calculating format, but I'm wondering how I can convert that data back into something humans can understand easily.
例如:
Chronic.parse('today') => 2011-02-17 17:30:00 -0500
所以有一种方法来采取2011 -02-18 20:00:00,并将其表示为2011年2月18日星期五下午10点?
So is there a way to take "2011-02-18 20:00:00 " and represent it as " Friday, February 18th, 2011 at 10pm "??
本质上与慢性相反? >
Essentially the reverse of Chronic?
推荐答案
看看strftime,这是一个链接到它是实施时间类。
Take a look at strftime, this is a link to it's implementation for the Time class.
有了它,你应该能够得到做任何事情的日期: - )
With it you should be able to get the date to do anything you want :-)
>> Time.now.strftime("%A, %B %d, %Y at %l%p")
=> "Thursday, February 17, 2011 at 5PM"
这篇关于Ruby / Rails - 将日期/时间转换成自然语言(2011-02-17 => 2011年2月17日)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!