dateformattingfxcopiformatprovider

Do I need to provide an IFormatProvider when converting a date to a string with a specific format?


If I'm using this:

DateTime.Now.Date.ToString("yyyy-MM-dd")

FXCop complains that I'm violating CA1305 and says that I should provider an IFormatProvider. Do I need to? I'm asking for the date in a specific format anyway (which is the format I'm expected to put it into the XML as).

Would providing a format provider make any difference? Might it actually produce the wrong results in this case?


Solution

  • so after a bit more research it seems that in my instance it doesn't make any difference, but in the general case months might be displayed in a specific locale.

    More details here:

    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx