-1

I am hitting a bit of a wall with this one.

I am currently trying to capture a DateTime in the format of yyyy-MM-ddTHH:mm:ss.fffZ as a string for an API call. However my original timestamp is currently formatted as a string like dd/MM/yyyy h:mm:ss tt.

My code is as follows:

string startingTimestamp = "04/28/2020 11:25:43 PM"

DateTime dt = DateTime.ParseExact(startingTimestamp, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
string finalTimestamp = dt.ToString("yyyy-MM-ddThh:mm:ss.fffZ");

What I would have expected to come out would be: 2020-04-28T23:25:43.511Z

But instead, I get: 2020-04-28T11:25:43.000Z.

In my debugging, I can see that the DateTime accounts for the PM, but it still outputs as 11:25 and not 23:25.

Am I missing some extra step to hard convert the DateTime to be 24H instead of 12H or is the toString method not the appropriate choice?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161

1 Answers1

0

Try HH for 24 hour. Use hh for 12 hour.

Adam V.
  • 16