另一個新手問題。我正在嘗試創建一個年齡計算器,它將用戶的年齡,然後從當前日期中減去並顯示給用戶。 我已經有了基本的想法。 這裏是我的示例代碼:如何創建一個年齡計算器,以年,日,年來講述年齡?
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