另一个新手问题。我正在尝试创建一个年龄计算器,它将用户的年龄,然后从当前日期中减去并显示给用户。 我已经有了基本的想法。 这里是我的示例代码:如何创建一个年龄计算器,以年,日,年来讲述年龄?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Age_Calculator
{
class Program
{
static void Main(string[] args)
{
DateTime Current = DateTime.Now;
Console.WriteLine("Please enter your birth date: ");
string myBirthDate = Console.ReadLine();
//ive got the date from the user, now how do i subtract the current date from the date of birth?
string myAge = //here the result is stored
//then displayed as hours
//then displayed as days
//finally as years
//will use replacement code i think
Console.WriteLine(myAge);
//Ive got the idea but due to lack of knowledge i cant make this application
}
}
}
采取今天的日期和减去诞生之日起,它应该给一个时间跨度的对象,你可以用它来得到你需要的信息。 – Jite