Calculate date of birth, age, sex (18-digit) according to the ID number. Practical skills for calculating seniority in entry time

Source: Internet
Author: User
Tags getdate
Applicable to the management of archives in OA project

1, according to the ID number calculation date of birth, age, sex (18-digit)
Copy Code code as follows:

Get input ID number
var Uusercard = $ ("#UUserCard"). Val ();
Get Date of birth
Uusercard.substring (6) + "-" + uusercard.substring (a) + "-" + uusercard.substring (12, 14);
Access to gender
if (parseint (Uusercard.substr (16, 1))% 2 = 1) {
Man
} else {
Woman
}
Get 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 < month | | Uusercard.substring = = Month && uusercard.substring (a) <= day) {
age++;
}
Age

2. Calculate the seniority according to the entry time
Copy Code code as follows:

Gets the entry time for the conversion to date
var utotime = $ ("#UToTime"). Val ();
var adate = Utotime.split ("-");
Because the month value is 0-11, the input month is reduced by one
var newdate = new Date (adate[0], adate[1]-1, adate[2]);
Current time
var mydate = new Date ();
Time subtraction to get millisecond value
var dif = Mydate.gettime ()-newdate.gettime ();
Mydate.settime (DIF);
The result is "1 years May 29"
Mydate.getfullyear ()-1970 + "Year" + mydate.getmonth () + "month" + mydate.getdate () + "Day"

Author: lying.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.