1,时间的格式化输出
t = Time.now
# to get day, month and year with century
# also hour, minute and second
puts t.strftime("%d/%m/%Y %H:%M:%S")
# You can use the upper case A and B to get the full
# name of the weekday and month, respectively
puts t.strftime("%A")
puts t.strftime("%B")
# You can use the lower case a and b to get the abbreviated
# name of the weekday and month, respectively
puts t.strftime("%a")
puts t.strftime("%b")
# 24 hour clock and Time zone name
puts t.strftime("at %H:%M %Z")
本文介绍了如何使用 Time.now 方法获取当前时间,并通过 strftime 函数来格式化输出日期和时间。包括了日期、时间、星期几及月份的不同格式展示,以及24小时制和时区名称的输出方式。
1581

被折叠的 条评论
为什么被折叠?



