Monday, July 22, 2013

DateTime country format

In cases when you need to work with a DateTime value in a particular country format (for example US or Australian) you can use CultureInfo to achieve this.
CultureInfo culture = new CultureInfo("en-AU");
DateTime reportDate = DateTime.Parse(txtDate.Text, culture);
The example above reads the DateTime variable in using the Australian format (dd/mm/yyyy). It comes in useful if the control is set to display US format for example.

No comments:

Post a Comment