Skip to content

Instantly share code, notes, and snippets.

@ywjno
Created May 9, 2012 08:02
Show Gist options
  • Save ywjno/2642824 to your computer and use it in GitHub Desktop.
Save ywjno/2642824 to your computer and use it in GitHub Desktop.
test Time.parse and Date.strptime method
# 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