Created
May 9, 2012 08:02
-
-
Save ywjno/2642824 to your computer and use it in GitHub Desktop.
test Time.parse and Date.strptime method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'date' | |
require 'time' | |
time = Time.parse("Wed, 9 May 2012 16:00:00 +0800") | |
# the src is like | |
#time = Time.parse("2012.05.09 16:00 +08:00") | |
puts time # 2012-05-09 16:00:00 +0800 | |
puts time.utc # 2012-05-09 08:00:00 UTC | |
puts time.getlocal("+09:00") # 2012-05-09 17:00:00 +0900 | |
puts time.getlocal("+07:00") # 2012-05-09 15:00:00 +0700 | |
date = Date.strptime("2012年5月9日", '%Y年%m月%d日') | |
puts date # 2012-05-09 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment