JRS: In article <5b************ **************@ posting.google. com>, seen
in news:comp.lang. javascript,
ti**********@ho tmail.com posted at Thu, 18
Sep 2003 01:30:48 :-
Im implementing a calendar and cant figure out what this method does
or how it works
// datetime parsing and formatting routimes. modify them if you wish
other datetime format
function str2dt (str_datetime) {
var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\: (\d+)\:(\d+)$/;
if (!re_date.exec( str_datetime))
return alert("Invalid Datetime format: "+ str_datetime);
return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4,
RegExp.$5, RegExp.$6));
In addition to what Lasse wrote : the function returns a Date Object set
to the browser's-locality date/time in the string, assuming that to be
of the form "D-M-Y h:m:s" where DMYhms are any number >0 of digits and
the date and time are separated by any amount of whitespace. If the
given year is in 00..99, 1900 will be added.
With whatever error there may be in the OS setting of Time Zone and
Summer Time rules; depending on the application, consequences may be
non-obvious or intermittent.
Twice, \ before - is not needed in the RegExp.
Any number can over/under-flow its field, so 31-9-2003 => 1-10-2003 and
25-0-2004 is this Christmas; in other words, there is no value
validation, only a pattern test. See via below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.