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

目录
相关文章
|
3月前
|
Shell
date $(date --date="2 days" +"%m%d")$(date +"%H%M")然后再输入date时间没变啊
date $(date --date="2 days" +"%m%d")$(date +"%H%M")然后再输入date时间没变啊
|
7月前
Date的Invalid Date
Date的Invalid Date
43 1
|
Java 关系型数据库 MySQL
Date和Calendar
Date和Calendar
125 0
|
存储 JavaScript 前端开发
new Date(dateString)
new Date(dateString)
114 0
new Date()
new Date()
114 0
LocalDate、LocalDateTime与timestamp、Date的转换
LocalDate、LocalDateTime与timestamp、Date的转换
921 0
|
安全 架构师 前端开发
你还在用 Date?快使用 LocalDateTime 了!
在项目开发过程中经常遇到时间处理,但是你真的用对了吗,理解阿里巴巴开发手册中禁用static修饰SimpleDateFormat吗?