江湖大侠
查看详细资料
TOP
栏目管理员
input = "8-9-2007 @ 23:00 pm" d=DateTime.parse(input) p d.class puts d.methods.sort
t = Time.now #=>Thu Aug 09 10:15:51 +0800 2007 year = t.year #=> 2007 month = t.month #=> 8 day = t.day #=> 9 hour = t.hour #=> 10 min = t.min #=> 15 sec = t.sec #=> 51
查看个人网站
江湖新秀
def toChiTime(time) time.strftime("%Y年%m月%d日 @ " + (time.strftime("%p") == "AM" ? "上午" : "下午" ) + " %H:%M") end puts toChiTime(Time.now) puts toChiTime(Time.now.to_s(:db))
爱睡觉的小猪
社区管理员
def time_to_str time,pattern="%Y年%m月%d日 %H:%M" time.strftime pattern unless time.nil? end
time_to_str Time.now
2007年08月11日 10:10
time_to_str Time.now,"%Y年%m月%d日"
2007年08月11日
time_to_str Time.now,"%m/%d %H:%M"
08/11 10:12
网站管理员
原帖由 skyover 于 2007-8-11 12:11 发表 楼上的没有解决上下午的显示问题。