![]() I don't understand the different results. The example illustrates how the conventions of a specific culture influence the formatting. ![]() The following example calls the Parse(String, IFormatProvider) method to parse the elements in a string array. String s = String.Format(new MyDateFormatProvider(), "", d) TimeSpan.Parse(String, IFormatProvider) method returns A time interval that corresponds to input, as specified by formatProvider. However, when I use the same class in the following way: DateTime d = new DateTime(2000, 1, 2) In that example, running in the US Culture, the result is "00cu0Ao00or0aA", apparently because the standard DateTime format strings are being interpreted. String s = d.ToString("mycustomformat", new MyDateFormatProvider()) I was expecting to be able to use it in the DateTime.ToString(string format, IFormatProvider provider) method like so, but : DateTime d = new DateTime(2000, 1, 2) ![]() If (arg.GetType() != typeof(DateTime)) return arg.ToString() If(arg = null) throw new ArgumentNullException("arg") Public string Format(string format, object arg, IFormatProvider formatProvider) If (formatType = typeof(ICustomFormatter)) Here is my implementation: public class MyDateFormatProvider : IFormatProvider, ICustomFormatter I was trying to create an IFormatProvider implementation that would recognize custom format strings for DateTime objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |