I have three integers: hours, minutes and seconds.
I want to create a DateTime object with System.Date and Time provided by the three variables listed above.
DateTime
Take a look at MSDN and look at the constructors that exist for DateTime , you will find out that this is possible:
var theDate = new DateTime (DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, hours, minute, second);
You can use DateTime.Today to get the current date at midnight, and add the hours you need using TimeSpan , which is a good way to represent the hours of the day:
DateTime.Today
TimeSpan
TimeSpan time = new TimeSpan(12, 20, 20); // hours, minutes, seconds DateTime todayWithTime = DateTime.Today + time;
See also:
See DateTime.Today and this DateTime constructor
DateTime today = DateTime.Today; new DateTime(today.Year, today.Month, today.Day, 10, 39, 30);
you have a constructor that accepts:
DateTime(Int32, Int32, Int32, Int32, Int32, Int32)
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second.
or you can just analyze the hours / minutes / seconds using DateTime.Parse() , which will automatically generate the current date (this is also written in the documentation)
DateTime.Parse()
Source: https://habr.com/ru/post/885397/More articles:Create a list in an Android application - androidUsing personal SSL certificates using Webdriver (Selenium 2.0) - javaPassing some LINQ query into function argument? - c #Count the various lines in C # code - stringReplace the string matching the specific regular expression with a length in Vim - vimSearch SQL test suite generator, ideally open source - sqlPlaying back Ruby OpenSSL private_encrypt output in C # - c #Set f: parameter value using JavaScript - javaNumber of samples in the series Exceedence - c #All Articles