📜  将 char 转换为字符串 c++ 代码示例

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

代码示例6
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"));
        }
    }
}