The below code is used to convert string (Date) to Date time and also it can be used for multiple Zones (Culture).
///
/// This method is used to convert date to date time.
///
///
/// returns datatime
private DateTime ConvertToDateTime(string strDateTime)
{
IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
DateTime dtFinaldate;
try
{
dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
}
catch (FormatException)
{
culture = new System.Globalization.CultureInfo("fr-FR", true);
dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
}
return dtFinaldate;
}
///
/// This method is used to convert date to date time.
///
///
///
private DateTime ConvertToDateTime(string strDateTime)
{
IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
DateTime dtFinaldate;
try
{
dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
}
catch (FormatException)
{
culture = new System.Globalization.CultureInfo("fr-FR", true);
dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
}
return dtFinaldate;
}
No comments:
Post a Comment