Date manipulation: Difference between revisions

→‎{{header|Ruby}}: add Ruby date class
m (moved Category to top)
(→‎{{header|Ruby}}: add Ruby date class)
Line 1,580:
 
=={{header|Ruby}}==
===Time class===
The <code>Time</code> package in the standard library adds a <code>parse</code> method to the core <code>Time</code> class.
 
Line 1,614 ⟶ 1,615:
new = t.in(12.hours)
new = t.advance(:hours => 12)</lang>
===Date class===
<lang Ruby>require "date"
 
str = "March 7 2009 7:30pm EST"
puts d1 = DateTime.parse(str)
# 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')</lang>
{{out}}
<pre>
2009-03-07T19:30:00-05:00
2009-03-08T07:30:00-05:00
2009-03-08T21:30:00+09:00
</pre>
 
=={{header|Run BASIC}}==
<lang runbasic>theDate$ = "March 7 2009 7:30pm EST"
1,149

edits