How to make a date in ISO 8601 format but still be a Datetime

Asked

Viewed 68 times

0

I wanted to know how I can transform a Datetime into an ISO 8601 format but keep it in a type of Datetime

1 answer

1


This is a form of representation of the date. A DateTime is a structure that tries to simulate a point in time (a date), as you will represent it date is not work of this structure itself.

You can use a .ToString("o") to represent a DateTime in ISO 8601 format.

string dataFormatada = minhaData.ToString("o");

See an example working on . NET Fiddle.

  • but so it won’t stay in string?

  • Youthful, one DateTime has no format. It’s a structure, you format to show, to serialize, something like that.

  • Exactly but there is no possibility to keep in Datetime ?

  • No, man. A Datetime has no format. You will format when you need.

  • How do I stop in an httpWebRequest.Date say that the date has to have this formatting ?

  • This is a header that is sent in the request. It is formatted with a specific format (see documentation: The classes in the System.Net namespace always write it out the Date property on the wire during transmission in standard form using GMT (Utc) format.). So, if you want to send this header differently, add it manually with the format you want to use.

  • Can you give me an example of how to do this ?

  • Of course. Your question of this question has been answered, right? Open a new question with the other specific question.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.