An extension of this question, I am pulling a date from a database and displaying it in a grid.
I have the following code:
string date = "";
DateTime? dateSent;
if (row["DateSent"] != DBNull.Value)
dateSent = (DateTime)row["DateSent"];
else dateSent = null;
date = (dateSent.HasValue ? dateSent.Value.ToString("dd/MM/yyyy hh:mm:ss") : null);
When I add a breakpoint at the end of this block of code, I can see that the DateTime?
variable "dateSent" has a 24-hour clock timestamp eg 14:50:34. However, when I check the value of the string
variable "date" - it has a 12-hour clock format eg 02:50:34.
It is not my intention to convert to a 12 hour clock format. I have two questions:
- Why is dateSent.Value.ToString("dd/MM/yyyy hh:mm:ss") returning a 12 hour clock timestamp?
- How can I avoid this and use the 24-hour clock version?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…