RosettaCodeData/Task/Date-manipulation/Zkl/date-manipulation-1.zkl

12 lines
390 B
Plaintext

var Date=Time.Date;
fcn add12h(dt){
re:=RegExp(0'|(\w+)\s+(\d+)\s+(\d+)\ +(.+)\s|);
re.search(dt);
_,M,D,Y,hms:=re.matched; //"March","7","2009","7:30pm"
M=Date.monthNames.index(M); //3
h,m,s:=Date.parseTime(hms); //19,30,0
dti:=T(Y,M,D, h,m,s).apply("toInt");
Y,M,D, h,m,s=Date.addHMS(dti,12);
"%s %d %d %s".fmt(Date.monthNames[M],D,Y,Date.toAMPMString(h,m));
}