18.2. Date

简介:

使用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 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
打赏
0
0
0
0
26197
分享
相关文章
date (datedate="2days"+"(date +"%H%M")然后再输入date时间没变啊
date (datedate="2days"+"(date +"%H%M")然后再输入date时间没变啊
|
10月前
Date的Invalid Date
Date的Invalid Date
63 1
to_date 和 sysdate
to_date 和 sysdate
936 0
new Date()
new Date()
126 0
LocalDate、LocalDateTime与timestamp、Date的转换
LocalDate、LocalDateTime与timestamp、Date的转换
962 0
你还在用 Date?快使用 LocalDateTime 了!
在项目开发过程中经常遇到时间处理,但是你真的用对了吗,理解阿里巴巴开发手册中禁用static修饰SimpleDateFormat吗?
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等