How do i convert this date 1/6/2016 12:00:00 AM
to 2016-01-06T00:00:00
in C#. I need to display it like that.
EstimatedDate.ToString("");
SOLVE:
string.Format("{0:s}", EstimatedDate)
You can use The "s"
standard format specifier which is exactly generate the result you want.
EstimatedDate.ToString("s");
From documentation;
The pattern reflects a defined standard (ISO 8601), and the property is read-only. Therefore, it is always the same, regardless of the culture used or the format provider supplied. The custom format string is
"yyyy'-'MM'-'dd'T'HH':'mm':'ss"
.
EstimatedDate.ToString("yyyy-MM-ddTHH:mm:ss");
sill give you the desired format
For a full example of:
DateTime date = DateTime.Parse("1/6/2016 12:00:00 AM");
string dateStr = date.ToString("yyyy-MM-ddTHH:mm:ss");
Update from @soner-gönül: - This method is Cultural dependent, where as "s"
is not. CurrentCulture
must be Gregorian Calendar for this to work.
cs timestamp time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With