Skip to content

Instantly share code, notes, and snippets.

@supasympa
Last active August 29, 2015 14:07
Show Gist options
  • Save supasympa/e76a20c334caa4a9d8cf to your computer and use it in GitHub Desktop.
Save supasympa/e76a20c334caa4a9d8cf to your computer and use it in GitHub Desktop.
/**
* gets the number of milliseconds from a date using a date format.
* @param dateString : the date to convert
* @param format : the format the date is in
* @returns Milliseconds from 01/01/1970
*/
return function (dateString, format){
function getDatePart(part){
var re, start, end;
re = new RegExp(part);
start = re.exec(format).index;
end = start + part.length;
return dateString.substring(start, end)
};
return (new Date(+getDatePart('yyyy'), +getDatePart('mm'), +getDatePart('dd'))).valueOf();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment