0lt
0lt

Reputation: 313

Creating DateTime object in Visual C++

I am familiar with creating DateTime object based on current system time

DateTime dtObject = DateTime::Now;

My question is: if I have integer variables iHour, iMinute and iSecond, how do I "put them back" into a DateTime object?

I hope I made myself clear. Thanks in advance!

Upvotes: 0

Views: 1135

Answers (1)

Igor Tandetnik
Igor Tandetnik

Reputation: 52471

Something along the lines of

DateTime today = DateTime::Today;
DateTime todayWithTime(today.Year, today.Month, today.Day,
                       hour, minute, second);

Another approach:

DateTime todayWithTime = DateTime::Today + TimeSpan(hour, minute, second);

Upvotes: 1

Related Questions