I have a C# DateTime object. This object includes both the date and time. I need to pass this information to a REST-based service. My question is, how do I format the DateTime,
For accuracy and consistency you could use:
string utcDateOut = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture);
DateTime utcDateIn = DateTime.ParseExact(utcDateOut, "s",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal);
This will give you an ISO 8601 compliant format and the use of UTC will ensure that there are no issues with time zones etc.
Only drawback is that it doesn't look as "nice" as a simple "yyyyMMdd".