Date manipulation: Difference between revisions

Replaced the program which used Posix functions by a program using the “times” module.
(Added Wren)
(Replaced the program which used Posix functions by a program using the “times” module.)
Line 1,690:
 
=={{header|Nim}}==
<lang nim>import posix, times
 
Timezones as “EST” are not recognized by the “times” module which follows ISO 8601 standard. So we replace it by a normalized timezone: -05:00. It would be easy to build a table to map these timezone identifiers to normalized timezones (being careful however regarding DST).
var ts: Ttm
 
discard "March 7 2009 7:30pm EST".strptime("%B %d %Y %I:%M%p %Z", ts)
We output the dates built after parsing in UTC. The module allows also to output in local time.
ts.tmHour += 12
 
echo ts.mktime</lang>
<lang nim>import posix, times
 
const Date = "March 7 2009 7:30pm EST"
echo "Original date is: ", Date
 
var dt = Date.replace("EST", "-05:00").parse("MMMM d yyyy h:mmtt zzz")
echo "Original date in UTC is: ", dt.utc().format("MMMM d yyyy h:mmtt zzz")
 
dt = dt + initDuration(hours = 12)
echo "Date 12 hours later is: ", dt.utc().format("MMMM d yyyy h:mmtt zzz")</lang>
 
{{out}}
<pre>SunOriginal Mardate is: 8 07:30:00 March 7 2009</pre> 7:30pm EST
Original date in UTC is: March 8 2009 12:30AM Z
Date 12 hours later is: March 8 2009 12:30PM Z</pre>
 
=={{header|ooRexx}}==
Anonymous user