DateTime time1 = new DateTime(2021, 3, 12, 15, 30, 0); // 3:30 PM DateTime time2 = time1.AddHours(1); // add 1 hour to time1
DateTime now = DateTime.Now; // get the current date and time DateTime tomorrow = now.AddHours(24); // add 24 hours to the current date and timeIn this example, we create a DateTime object called now with the current date and time. We then use the AddHours function to add 24 hours to now and store the result in a new DateTime object called tomorrow. This will give us the date and time exactly 24 hours from now. From these examples, we can determine that the Time AddHours function is part of the System.DateTime structure in the System package library.