Date manipulation: Difference between revisions

Added zkl
(Added Erlang)
(Added zkl)
Line 1,800:
<pre>Sun Mar 8 08:30:00 EDT 2009
Sun Mar 8 20:30:00 CST 2009</pre>
 
=={{header|zkl}}==
The iso8601 library offers additional Time/Date support but using the built in stuff:
<lang zkl>var D=Time.Date;
fcn add12h(dt){
re:=RegExp(0'|(\w+)\s+(\d+)\s+(\d+)\ +(.+)\s|);
re.search(dt);
_,mon,d,y,hms:=re.matched; //"March","7","2009","7:30pm"
mon=D.monthNames.index(mon); //3
h,m,s:=D.parseTime(hms); //19,30,0
o,h:=(h+12).divr(24); //1,7
if(o) d=d.toInt()+1;
// need to check for month/year roll
// the Date library offers serveral ways to format, but I'll copy the given format
"%s %d %d %s".fmt(D.monthNames[mon],d,y,D.toAMPMString(h,m));
}
add12h("March 7 2009 7:30pm EST").println();</lang>
{{out}}<pre>March 8 2009 07:30AM</pre>
 
 
{{omit from|ML/I}}
{{omit from|PARI/GP|No real capacity for string manipulation}}
Anonymous user