Fiendcoder1 Fiendcoder1 - 1 year ago 83
C# Question

Storing DateTime into Array in c#

I have initialized an array for my


DateTime[] departureCalcArray = new DateTime[10];

And then getting the value of the
that is formatted as
h:mm tt
(that is 8:30 AM with no preceeding zero) .

My code for storing the value of the
is as below.

departureCalcArray[i] = timeDeparture.Value.Date;

However, when I checked if the value is saved via

I keep getting the date today and 12:00:00 AM. Although back in PHP, I use to convert the time to 24hour format so that I can use it in calculation. Any help please?

Answer Source


departureCalcArray[i] = timeDeparture.Value.Date;


departureCalcArray[i] = timeDeparture.Value;

When you use the Date property of a DateTime instance, you get a new DateTime instance with the same date, but its Time component set to 12:00AM

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download