W
Wajih-ur-Rehman
I want to convert a DateTime Object to a string and the conversion should be
such that it should work irrespective of locale of the current system.
I have used the following code to accomplish this:
CultureInfo c = new
CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, true);
DateTimeFormatInfo d = c.DateTimeFormat;
d.DateSeparator = "/";
// dt is a DateTime object
string finalString = dt.ToString("MM/dd/yyyy hh:mm:ss tt",d);
but unfortunately it is not running correctly on all locales. For example;
it fails for locale Czech. When i say fail, i mean that while inserting this
date in the database an exception is thrown by the DB that its not a valid
format for DateTime. Any idea what i am doing wrong? or how i can make it
work independent of locale. I would really appreciate any help.
Regards
Wajih
such that it should work irrespective of locale of the current system.
I have used the following code to accomplish this:
CultureInfo c = new
CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name, true);
DateTimeFormatInfo d = c.DateTimeFormat;
d.DateSeparator = "/";
// dt is a DateTime object
string finalString = dt.ToString("MM/dd/yyyy hh:mm:ss tt",d);
but unfortunately it is not running correctly on all locales. For example;
it fails for locale Czech. When i say fail, i mean that while inserting this
date in the database an exception is thrown by the DB that its not a valid
format for DateTime. Any idea what i am doing wrong? or how i can make it
work independent of locale. I would really appreciate any help.
Regards
Wajih