📜  将 char 转换为 C - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:54.039000             🧑  作者: Mango

代码示例1
using System;

namespace Dates
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter date");
            string dateInput = Console.ReadLine();
            Console.WriteLine("Enter time");
            string timeInput = Console.ReadLine();
            Console.WriteLine("Enter number of hours to add");
            string hoursInput = Console.ReadLine();

            int hours = int.Parse(hoursInput);
            
            string[] timeParts =  timeInput.Split(":");
            string[] dateParts = dateInput.Split("-");

            DateTime date = new DateTime(
                int.Parse(dateParts[0]),
                int.Parse(dateParts[1]),
                int.Parse(dateParts[2]),
                int.Parse(timeParts[0]),
                int.Parse(timeParts[1]),
                0
            );

            date = date.AddHours(hours);
            Console.WriteLine(date.ToString("yyyy-MM-dd HH:mm"));
        }
    }
}