The birth date, age, and gender (18 digits) are calculated based on the ID card number. The length of service is calculated based on the start time.

Source: Internet
Author: User

Applies to the management of archives in OA projects.

1. Calculate the birth date, age, and gender (18 digits) based on the ID card number)
Copy codeThe Code is as follows:
// Obtain the input ID number
Var UUserCard = $ ("# UUserCard"). val ();
// Obtain the Date of birth
// UUserCard. substring (6, 10) + "-" + UUserCard. substring (10, 12) + "-" + UUserCard. substring (12, 14 );
// Obtain gender
If (parseInt (UUserCard. substr (16, 1) % 2 = 1 ){
// Male
} Else {
// Female
}
// Obtain the 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

2. Calculate the length of service based on the start time
Copy codeThe Code is as follows:
// Obtain the input entry time and convert it to Date
Var UToTime = $ ("# UToTime"). val ();
Var aDate = UToTime. split ("-");
// Because the month value ranges from 0 to 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 ();
// Subtract time to get the millisecond Value
Var dif = myDate. getTime ()-NewDate. getTime ();
MyDate. setTime (dif );
// The result is [May 29 ].
// MyDate. getFullYear ()-1970 + "year" + myDate. getMonth () + "month" + myDate. getDate () + "day"

Author: LyIng. Net

Related Article

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.