How to convert time to c #

How do I convert this date 1/6/2016 12:00:00 AMto 2016-01-06T00:00:00in C #. I need to display it like this.

EstimatedDate.ToString("");

DECIDE:

string.Format("{0:s}", EstimatedDate)
+4
source share
2 answers

You can use a standard format specifier"s" that accurately generates the desired result.

EstimatedDate.ToString("s");

From the documentation;

The sample reflects a specific standard ( ISO 8601 ), and the property is read-only. Therefore, it is always the same, regardless of the culture used or the format provider. Custom format string "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

+9
source

EstimatedDate.ToString("yyyy-MM-ddTHH:mm:ss"); threshold gives you the desired format

For a complete example:

DateTime date = DateTime.Parse("1/6/2016 12:00:00 AM");
string dateStr = date.ToString("yyyy-MM-ddTHH:mm:ss");

@soner-gönül:. , "s" . CurrentCulture .

+4

Source: https://habr.com/ru/post/1624748/


All Articles