A method analysis of accurate age calculation in C #

Source: Internet
Author: User
Tags sqlite database

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 #

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.