Date manipulation: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: typeo |
m {{out}} |
||
Line 1:
{{task|Text processing}}
Given the date string "March 7 2009 7:30pm EST",
output the time 12 hours later in any human-readable format.
As extra credit, display the resulting time in a time zone different from your own.
=={{header|Ada}}==
The Ada way: long, type-based, clear, reliable.
Line 186 ⟶ 188:
Return, Result
}</lang>
{{out|Message box shows
<pre>Given: March 7 2009 7:30pm EST
Line 214 ⟶ 216:
}
</lang>
{{out}}
<pre>
time: Sat 2009-03-07 19:30:00 Eastern Standard Time
+12 hrs: Sun 2009-03-08 08:30:00 Eastern Daylight Time
</pre>
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
Line 254 ⟶ 257:
ENDPROC
</lang>
{{out}}
<pre>March 8 2009 7:30am EST
March 8 2009 12:30pm GMT
Line 371 ⟶ 374:
}
</lang>
{{out}}
<pre>
local time: 2009-Mar-07 19:30:00 EST
Line 477 ⟶ 480:
</lang>
{{out}}
"03/08/2009 07:30 AM"
----
Line 543 ⟶ 547:
printf(1, "%s EST\n", {format(dt, "%B %d %Y %I:%M %p")})
</lang>
{{out}}
<pre>
March 08 2009 07:30 AM EST
Line 566 ⟶ 570:
main()</lang>
<pre>Original date in local time : 08.03.2009 01:30:00
Original date in EST : 07.03.2009 19:30:00
Line 587 ⟶ 591:
=={{header|Frink}}==
Frink parses a large number of date/time formats, has robust date/time math,
and automatically converts between timezones.
By default, output times are in the user's defined timezone.
<lang frink>
### MMM dd yyyy h:mma ###
Line 595 ⟶ 601:
</lang>
{{out}}
<pre>
AD 2009-03-08 AM 08:30:00.000 (Sun) Eastern Daylight Time
Line 675 ⟶ 680:
println (dt.plusHours(12).withZone(DateTimeZone.UTC))</lang>
{{out}}
<pre>2009-03-07T18:30:00.000-06:00
2009-03-08T07:30:00.000-05:00
Line 779 ⟶ 784:
[http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime provides SecToDateLine, and DateLineToSec] these convert between Icon's &dateline format and seconds from a configurable base date (which defaults to the normal 1970 epoch).
{{out}}
+12 hours = Sunday, March 8, 2009 7:30 am EST
= Sunday, March 8, 2009 12:30 pm UTC
Line 801 ⟶ 807:
}</lang>
{{out}}
<pre>March 8 2009 8:30AM EDT</pre>
or using <tt>System.out.println(date);</tt> as the last line:
Line 811 ⟶ 817:
Input: March 7 2009 7:30pm EST
The input string is ambiguous since EST might represent
any one of 3 different world time zones.
Will assume US Eastern Standard Time of UTC -5 hours.
Javascript date objects are always in the local time zone.
Consequently, there may be issues if daylight saving is observed in one location but not the other.
While ECMA-262 Ed 5 specifies a <code>Date.parse</code> method, it is not widely supported (2011) and parsing of strings other than the format specified are implementation dependent. Since the test string doesn't conform to the standard, it must be manually parsed.
Line 897 ⟶ 907:
print( os.date( "%c", os.time{ year=year, month=month, day=day, hour=hour, min=min, sec=0 } + 12 * 3600 ) )
</lang>
{{out}}
<pre>Sun Mar 8 07:30:00 2009</pre>
Line 938 ⟶ 948:
return
</lang>
{{out}}
<pre>
March 7 2009 7:30pm EST
Line 951 ⟶ 961:
ts.tmHour += 12
echo ts.mktime</lang>
{{out}}
<pre>Sun Mar 8 07:30:00 2009</pre>
Line 1,305 ⟶ 1,315:
*/
</lang>
{{out}}
<pre>
Manipulate the date string "March 7 2009 7:30pm EST" and present results in ISO 8601 timestamp format:
Line 1,345 ⟶ 1,355:
If we're given an ambiguous timezone like 'EST' for input, we can handle this by changing it to the unambiguous Olson timezone id. This ensures daylight savings is correctly handled (which is especially tricky here, since March 7/8 is the DST rollover, and times jump ahead skipping an hour)
{{out}}
<pre>March 8 2009 6:30AM MDT</pre>
=={{header|Perl 6}}==
Perl 6 comes with a build-in DateTime type
to support most aspects of standard civic time calculation
Perl 6 does not yet have a date parsing module (mostly due to a reticence to inflict Western cultural imperialism on other cultures...or maybe just due to laziness), but that just gives us another opportunity to demonstrate the built-in grammar support.▼
that are not dependent on cultural idiosyncracies. <br>
Unfortunately, Perl 6 does not yet have a date parsing module
(mostly due to a reticence to inflict Western cultural imperialism on other cultures...
▲
<lang perl6>my @month = <January February March April May June July August September October November December>;
Line 1,455 ⟶ 1,470:
write-host $date.AddHours(12)
write-host [TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($date.AddHours(12),"Vladivostok Standard Time")</lang>
<pre>domingo, 08 de marzo de 2009 1:30:00
domingo, 08 de marzo de 2009 13:30:00
Line 1,504 ⟶ 1,519:
"~a ~d ~b ~Y ~H:~M")
</lang>
{{out}}
<lang racket>
"Sun 08 Mar 2009 07:30"
Line 1,538 ⟶ 1,553:
</lang>
{{out}}
<pre>8-Mar-2009/7:30-5:00</pre>
Line 1,557 ⟶ 1,571:
say aDate ' + 12 hours ───► ' ndate ntime tz /*display new timestamp.*/
/*stick a fork in it, we're done.*/</lang>
{{out}}
<pre style="overflow:scroll">
March 7 2009 7:30pm EST + 12 hours ───► 8 Mar 2009 7:30am EST
Line 1,585 ⟶ 1,599:
puts remote.rfc2822
puts remote.zone</lang>
{{out}}
<pre>Sat, 07 Mar 2009 19:30:00 -0500
EST
Line 1,636 ⟶ 1,650:
}</lang>
{{out}}
<pre>March 8 2009 8:30AM EDT
March 8 2009 12:30PM GMT</pre>
Line 1,694 ⟶ 1,708:
end func;</lang>
{{out}}
<pre>
Given: 2009-03-07 19:30:00 UTC-5
Line 1,793 ⟶ 1,807:
(dt dateTime) asUTC displayNl.</lang>
<pre>March 8 2009 8:30AM EST
2009-03-08T13:30:00+00:00</pre>
Line 1,814 ⟶ 1,827:
TZ=Asia/Shanghai date -d @$epoch</lang>
{{out}}
<pre>Sun Mar 8 08:30:00 EDT 2009
Sun Mar 8 20:30:00 CST 2009</pre>
|