How to serialise DateTime with seconds displayed as 0?

c#, datetime

Solution

If the purpose is to only show `00` seconds then just replace `ss` with `00`

dtDateTime.ToString("M/dd/yyyy h:mm:00 tt", CultureInfo.InvariantCulture)

Problem

I have some DateTime's that will be calculated in the format: `dtDateTime.ToString("M/dd/yyyy h:mm:ss tt")` and I want to keep the `ss` formatting but just set the value to zero. Example: Before Change: `"7/14/2014 7:34:27 AM"` After Change: `"7/14/2014 7:34:00 AM"` What I have tried: ``` dtDateTime = my DateTime TimeSpan secondsDifference = dtDateTime.Subtract(new System.DateTime(0, 0, 0, 0, 0, dtDateTime.Second) dtDateTime = dtDateTime.Date - secondsDifference; return dtDateTime.ToString("M/dd/yyyy h:mm:ss tt") ``` This gives me an error, on the `dtDateTime.Subtract()` expression because this date is before 1970, when (I think) Unix Time stamping started. How can I simply set the `seconds` part of `dtDateTime` to `00`? NB - code brevity is important. Thanks all.

Original source

Related problems