In our application, we build date selection menus based on month end dates that are determined programmatically. In the US, a date might be 12/31/2012. In France, it might be 31/12/2012 or it could be a slightly different format that I get from CultureInfo.
My question is this: If I have a string date such as 12/31/2012 that is generated by the application – how can I format it properly for the culture the application is being run in? I can’t convert the string to a date and then format it, because I don’t know ahead of time what culture the application is being run in and what constitutes a valid date. Am I going to have to parse the short date format to try to display the date properly?
Yes, you can. You can both parse it to a
DateTimeand format it using the current culture.VB.NET:
C#: