The examples in this paper describe how to calculate age accurately in C #. Share to everyone for your reference. Specific as follows:
The source code in the VS2010 test passed
The code is as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Publicclass
{
public static Class Calculationdate
{
<summary>
Age (years, months, days) calculated from two dates
</summary>
public static void Calculationdate (DateTime begindatetime, DateTime enddatetime)
{
if (Begindatetime > EndDateTime)
throw new Exception ("Start time should be less than or equal to the end time!") ”);
/* Calculate the total number of months from the date of birth to the current date */
int Months = enddatetime.month–begindatetime.month + * (enddatetime.year–begindatetime.year);
/* After the date of birth plus the total number of months, minus one months if it is greater than the current date */
int totalmonth = (begindatetime.addmonths (Months) > EndDateTime)? Months–1:months;
/* Calculate all Year */
int fullyear = TOTALMONTH/12;
/* Calculate entire month */
int fullmonth = totalmonth% 12;
/* Count days */
DateTime changedate = begindatetime.addmonths (totalmonth);
Double days = (enddatetime–changedate). Totaldays;
}
}
}
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
A method analysis of accurate age calculation in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23104.html
Related content C # Getting Started Tutorial collection ArrayList usage details C # Operations SQLite Database Method Summary (create, join, insert, query, delete, etc.) C # Implement a form pass-through instance analysis for C # brushes method for drawing a single rectangle using a composite array
The difference between IEnumerable, ICollection, IList, and list in C # computes the method of file MD5 checksum C # path. GetFullPath how to get a parent directory implementation method C # generic Dictionary usage examples
A method analysis of accurate age calculation in C #