Calculate the date of birth age and gender (18) according to the id card number and calculate the length of service according to the entry time
- 2020-05-17 05:14:41
- OfStack
This applies to the management of these files in the OA project
1. Calculate the date of birth, age and gender (18 digits) according to the id card number
2. Calculate the length of service according to the entry time
Author: LyIng Net
1. Calculate the date of birth, age and gender (18 digits) according to the id card number
// Get input id number
var UUserCard = $("#UUserCard").val();
// Get the date of birth
//UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
// For gender
if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
// male
} else {
// female
}
// For age
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
age++;
}
// age age
2. Calculate the length of service according to the entry time
// Gets the input entry time converted to Date
var UToTime = $("#UToTime").val();
var aDate = UToTime.split("-");
// Because of the month 0-11 So let's subtract the input month 1
var NewDate = new Date(aDate[0], aDate[1] - 1, aDate[2]);
// The current time
var myDate = new Date();
// You subtract the time to get the value of milliseconds
var dif = myDate.getTime() - NewDate.getTime();
myDate.setTime(dif);
// The results for" 1 years 5 month 29 Day 】 this
//myDate.getFullYear() - 1970 + " years " + myDate.getMonth() + " month " + myDate.getDate() + " day "
Author: LyIng Net