How does one convert a .Net DateTime into a valid HTTP-formatted date string?
var ci = new CultureInfo("en-US"); ci. DateTimeFormat. ShortDatePattern = "MM/dd/yyyy"; app.
string date = DateTime. ParseExact(SourceDate, "dd/MM/yyyy", CultureInfo. InvariantCulture). ToString("yyyy-MM-dd");
Dates can be converted to HTTP valid dates (RFC 1123) by using the "r" format string in .Net. HTTP dates need to be GMT / not offset - this can be done using the ToUniversalTime() method.
So, in C# for example:
string HttpDate = SomeDate.ToUniversalTime().ToString("r");
Right now, that produces HttpDate = "Sat, 16 Aug 2008 10:38:39 GMT"
See Standard Date and Time Format Strings for a list of .Net standard date & time format strings.
See Protocol Parameters for the HTTP date specification, and background to other valid (but dated) RFC types for HTTP dates.
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