Thursday, March 1, 2012
This is a code that can be used to get birth day from National Identity Card in Sri Lanka.
public Calendar getBirthDate(String nic) {
int date = Integer.valueOf(nic.substring(2, 5));
int bdate = 0;
int bmonth = 0;
int byear = Integer.valueOf(nic.substring(0, 2));
if (date > 500) {
date = date - 500;
}
if (date <= 31) {
bdate = date;
bmonth = 1;
}
if (31 < date & date <= 60) {
bdate = date - 31;
bmonth = 2;
}
if (60 < date & date <= 91) {
bdate = date - 60;
bmonth = 3;
}
if (91 < date & date <= 121) {
bdate = date - 91;
bmonth = 4;
}
if (121 < date & date <= 152) {
bdate = date - 121;
bmonth = 5;
}
if (152 < date & date <= 182) {
bdate = date - 152;
bmonth = 6;
}
if (182 < date & date <= 213) {
bdate = date - 182;
bmonth = 7;
}
if (213 < date & date <= 244) {
bdate = date - 213;
bmonth = 8;
}
if (244 < date & date <= 274) {
bdate = date - 244;
bmonth = 9;
}
if (274 < date & date <= 305) {
bdate = date - 274;
bmonth = 10;
}
if (305 < date & date <= 335) {
bdate = date - 305;
bmonth = 11;
}
if (335 < date & date <= 366) {
bdate = date - 335;
bmonth = 12;
}
Calendar calendar = Calendar.getInstance();
calendar.clear();
byear = getYear(byear);
calendar.set(Calendar.YEAR, byear);
calendar.set(Calendar.MONTH, bmonth);
calendar.set(Calendar.DATE, bdate);
return calendar;
}