When displaying my DateTime values, I want them to be formatted like so: ‘February 9, 2009 7:00 AM’
I am using the following code, but am concerned that the date may display incorrectly in other cultures. Can anyone tell me if this is the case or not, and if it is how can I fix it?
Date.ToString('MMMM dd, yyyy hh:mm tt');
Thanks!
What exactly is ‘correct’? Are you a normal client-side app? If so, you’ll get localised month names. Is that ‘incorrect’? Depends what you’re looking for.
If you do want locale-friendly times in a client-side app then using the default long date format will give you the smoothest results. In my locale I wouldn’t want to see 12-hour clock or the month before the day, though I’d surely understand it.
If you’re a server-side app you don’t want to use any default-localised anything, because the locale will be your server’s rather than your users’, and you’ll have a weird portability problem. In this case you’ll have to either allow the user to pick out their own locale, or use your own date formatting functions with built-in English month names.
(Or, to avoid the problem, no month names. In which case ISO-8601 format “YYYY-mm-dd HH:MM:SS” would be the default choice.)