using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 時間間隔獲取控制台
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("=========== 時間間隔計算助手 ==============");
Console.WriteLine("==== 本軟件源碼地址:www.etwiki.cn =====");
while (true)
{
try
{
GetDifTime();
}
catch (Exception)
{
Console.WriteLine("輸入時間有誤!");
}
}
}
public static void GetDifTime()
{
int year, mouth, day;
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("請輸入要計算的年數(0000-9999)");
year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入要計算的月(1-12)");
mouth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入日(1-31)");
day = Convert.ToInt32(Console.ReadLine());
DateTime d1 = DateTime.Now;
DateTime d2 = new DateTime(year, mouth, day);
TimeSpan d3 = d2.Subtract(d1);
int d4 = d2.CompareTo(d1);
if (d4 == -1)//過去時間
{
//Console.Clear();
Console.WriteLine("您輸入的時間為過去的時間!");
Console.WriteLine("當前