I\'m trying to get JavaScript to parse a date and time format for me, with the eventual aim of telling me the days passed since that date and the time right now (locally).
This should do it
function dateFromUTC( dateAsString, ymdDelimiter )
{
var pattern = new RegExp( "(\\d{4})" + ymdDelimiter + "(\\d{2})" + ymdDelimiter + "(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})" );
var parts = dateAsString.match( pattern );
return new Date( Date.UTC(
parseInt( parts[1] )
, parseInt( parts[2], 10 ) - 1
, parseInt( parts[3], 10 )
, parseInt( parts[4], 10 )
, parseInt( parts[5], 10 )
, parseInt( parts[6], 10 )
, 0
));
}
alert( dateFromUTC( "2008-10-01 06:21:43", '-' ) );