2017-08-22 149 views
-11
namespace Computerization_of_Health_Records 
{ 
    public class HealthProfile 
    { 
     //auto implemented property Firstname implicitly creates an 
     //instance variable for the patients first name 
     public string FirstName { get; set; } 

     //auto implemented property Firstname implicitly creates an 
     //instance variable for the patients last name 
     public string LastName { get; set; } 

     //auto implemented property Gender implicitly creates an 
     //instance variable for the patients gender 
     public string Gender { get; set; } 

     //auto implemented property birthday implicitly creates an 
     //instance variable for the patients birth day 
     public Int32 Birthday { get; set; } 

     //auto implemented property height implicitly creates an 
     //instance variable for the patients height 
     public string Height { get; set; } 

     //auto implemented property weight implicitly creates an 
     //instance variable for the patients weight 
     public string Weight { get; set; } 

     public string maxHeartRate { get; set; } 

     public string bmi { get; set; } 

     public string Age { get; set; } 


     //constructor to initialize first name, last name, gender, birthday, birth month, 
     //Birth year, height and weight. 
     public HealthProfile(string first, string last, string gender, Int32 birthday, string height, string weight, string maxHrtRate) 
     { 
      FirstName = first; 
      LastName = last; 
      Gender = gender; 
      Birthday = birthday; 
      Height = height; 
      Weight = weight; 
      maxHeartRate = maxHrtRate; 
     } 


    } 



    } 
+0

什么是“TIA”?为什么这么多代码与问题无关? – tadman

+0

问题中的任何代码与计算出生日期有什么关系? – Amy

+0

您的生日变量是Int32。除非它至少是时间跨度值,否则您将无法计算年龄。 – Amit

回答

-1

通日期UTC格式下面的函数(作为其标准的日期格式)

public static string GetAge(DateTime dob) 
{ 
      DateTime todayDateUtc = DateTime.UtcNow; 
      DateTime pastYearDate; 
      int years=0; 
      string age; 
      int days; 

      if(DateTime.UtcNow > dob) 
        years = new DateTime(DateTime.UtcNow.Subtract(dob).Ticks).Year - 1; 

       pastYearDate = dob.AddYears(years); 
       days = todayDateUtc.Subtract(pastYearDate).Days; 
       age = years + " years " + days + " days"; 
      return age; 
} 
相关问题