使用strftime获得具体的年份,月份或日期等等,常用:
CODE OUTPUT DESCRIPTION t.strftime("%H") => "22" # Gives Hour of the time in 24 hour clock format t.strftime("%I") => "10" # Gives Hour of the time in 12 hour clock format t.strftime("%M") => "49" # Gives Minutes of the time t.strftime("%S") => "27" # Gives Seconds of the time t.strftime("%Y") => "2013" # Gives Year of the time t.strftime("%m") => "09" # Gives month of the time t.strftime("%d") => "12" # Gives day of month of the time t.strftime("%w") => "4" # Gives day of week of the time t.strftime("%a") => "Thu" # Gives name of week day in short form of the t.strftime("%A") => "Thursday" # Gives week day in full form of the time t.strftime("%b") => "Sep" # Gives month in short form of the time t.strftime("%B") => "September" # Gives month in full form of the time t.strftime("%y") => "13" # Gives year without century of the time t.strftime("%Y") => "2013" # Gives year without century of the time t.strftime("%Z") => "IST" # Gives Time Zone of the time t.strftime("%p") => "PM" # Gives AM / PM of the time
# 2012-03-06 15:28:08 puts Time.now.strftime("%Y-%m-%d %H:%M:%S") # 03/06/12 03:39 PM puts Time.now.strftime("%x %I:%M %p")
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。