Let’s say I have a DatePicker
control and I allow my US clients to type something like
"1/1"
in it and hit tab go to next control. So I will parse that date for them as “01/01/2014” and some more similar patterns. But they are all US-based so they are
"MM/dd/yyyy"
Now my question is about other formats? What If I want to support a country format that is like "yyyy/mm/dd"
. How do those countries interpret such patterns?
You can use culture related format provider or directly use custom format when translating DateTime to String.
If you use VS 2010 and above, read this in MSDN Library starting from DateTime documentation:
http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.100%29.aspx
And also this for custom date and time format:
http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.100%29.aspx
I don’t believe there is any standard way of how this should work, but I think you can assume if they are only entering two parts of the date those parts are the day and month (unless the system has a specific requirement otherwise). But you need to put a bit of intelligence in there, for example date format might be yyyy.mm.dd. You algorithm should ideally be generic based on locale.