Creating a DateTime in C #

How would I dynamically create an object DateTimethat always has the current month / day / year but always has a 16:00 time component?

+5
source share
2 answers

You can do it:

 var today = DateTime.Today.AddHours(16);

It should be today, at 16:00 (16:00)

+7
source

What about:

DateTime today = DateTime.Today;
DateTime Today16 = new DateTime(today.Year, today.Month, today.Day,
                                16, 0, 0)

This should use the year, month, day today and set the time to 4:00 p.m.

+4
source

All Articles