Search code examples
c#.netwinformsdatetimedatetimepicker

Use DateTime Format Strings in a Custom DateTimePickerFormat


Everywhere in my code, when dealing with dates, I rely on the DateTime Format String "G". EXCEPT in the DateTimePicker itself, as I must set a CustomFormat, and the CustomFormat doesn't accept "G" as a valid format specifier. I need this so that the dates will all look the same, independent of culture.

Any thoughts on how I might circumvent this issue?


Solution

  • The following code should work:

    picker.CustomFormat = DateTimeFormatInfo.ShortDatePattern +  DateTimeFormatInfo.LongTimePattern
    

    This is essentially what the "G" format specifier gives you.