Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Date-manipulation/Ruby/date-manipulation-1.rb
Normal file
18
Task/Date-manipulation/Ruby/date-manipulation-1.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
require 'time'
|
||||
d = "March 7 2009 7:30pm EST"
|
||||
t = Time.parse(d)
|
||||
puts t.rfc2822
|
||||
puts t.zone
|
||||
|
||||
new = t + 12*3600
|
||||
puts new.rfc2822
|
||||
puts new.zone
|
||||
|
||||
# another timezone
|
||||
require 'rubygems'
|
||||
require 'active_support'
|
||||
zone = ActiveSupport::TimeZone['Beijing']
|
||||
remote = zone.at(new)
|
||||
# or, remote = new.in_time_zone('Beijing')
|
||||
puts remote.rfc2822
|
||||
puts remote.zone
|
||||
3
Task/Date-manipulation/Ruby/date-manipulation-2.rb
Normal file
3
Task/Date-manipulation/Ruby/date-manipulation-2.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
new = t + 12.hours
|
||||
new = t.in(12.hours)
|
||||
new = t.advance(:hours => 12)
|
||||
6
Task/Date-manipulation/Ruby/date-manipulation-3.rb
Normal file
6
Task/Date-manipulation/Ruby/date-manipulation-3.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
require "date"
|
||||
|
||||
puts d1 = DateTime.parse("March 7 2009 7:30pm EST")
|
||||
# d1 + 1 would add a day, so add half a day:
|
||||
puts d2 = d1 + 1/2r # 1/2r is a rational; 0.5 would also work
|
||||
puts d3 = d2.new_offset('+09:00')
|
||||
Loading…
Add table
Add a link
Reference in a new issue