---
title: "ruby学习笔记--Time&DateTime"
author: "minstrel"
date: "2008-01-04T08:42:59Z"
tags: []
slug: "ruby-time-datetime"
draft: false
lastmod: "2008-01-04T08:42:59Z"
id: 152991
url: "https://minstrel.iteye.com/blog/152991"
---

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") 
```