Skip to content

Instantly share code, notes, and snippets.

@afiqiqmal
Forked from crynobone/Birthdate Parser.js
Created November 9, 2017 09:33
Show Gist options
  • Save afiqiqmal/1b5f31c5ee9d8efdc3225eeb421b411b to your computer and use it in GitHub Desktop.
Save afiqiqmal/1b5f31c5ee9d8efdc3225eeb421b411b to your computer and use it in GitHub Desktop.
Malaysia Indentification Card Number to Birthdate
var ic = '090303086521';
if(ic.match(/^(\d{2})(\d{2})(\d{2})-?\d{2}-?\d{4}$/)) {
var year = RegExp.$1;
var month = RegExp.$2;
var day = RegExp.$3;
console.log(year, month, day);
var now = new Date().getFullYear().toString();
var decade = now.substr(0, 2);
if (now.substr(2,2) > year) {
year = parseInt(decade.concat(year.toString()), 10);
}
var date = new Date(year, (month - 1), day, 0, 0, 0, 0);
console.log(date);
}
else {
// not a proper IC format
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment