数据映射器日期
如果这是一个简单的答案,请原谅我。
但是如何从 DataMapper 属性获取日期。例如:
require 'rubygems'
require 'sinatra'
require 'datamapper'
class Test
include DataMapper::Resource
property :id, Serial
property :created_at, Date
end
get '/:id' do
test = Test.get(1)
test.created_at = ?
end
Forgive me if this is a simple answer.
But how do you get a Date from a DataMapper property. For example:
require 'rubygems'
require 'sinatra'
require 'datamapper'
class Test
include DataMapper::Resource
property :id, Serial
property :created_at, Date
end
get '/:id' do
test = Test.get(1)
test.created_at = ?
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下功能访问它
http://ruby-doc.org/core/classes/DateTime.html
例如:
将返回格式为 YYYY-MM-DD HH:MM:SS 的日期,
这有帮助吗?
You can access it with the functions from
http://ruby-doc.org/core/classes/DateTime.html
For example:
will return a date formatted YYYY-MM-DD HH:MM:SS
Does that help?
或者确实
返回一个日期,例如
2011-07-14 00:09:32 +0100
,包括偏移量。或者
返回以本地格式定义的日期,例如
Thu Jul 14 00:09:32 2011
。或者
返回 ISO 8601 格式的日期,例如
2011-07-14T00:09:32+01:00
。哦,而且没有必要指定
fmt=
;但是,如果您只想要日期,则可以
返回
“2011-07-14”
。另请记住,如果您只想存储日期而不是日期时间,则可以使用
created_on
。Or indeed
returns a date such as
2011-07-14 00:09:32 +0100
, including the offset.Or
returns a date defined in the local format, such as
Thu Jul 14 00:09:32 2011
.Or either of
returns a date in ISO 8601 format, such as
2011-07-14T00:09:32+01:00
.Oh, and it isn't necessary to specify
fmt=
; you can doHowever, if you just want the date, you can do
which returns
"2011-07-14"
.Bear in mind, also, that you can use
created_on
, if you only want to store a Date, and never a DateTime.