I need to convert DateTime
value in different culture format, whatever set in system.
There is not any specific TimeZone selected for converting, any culture format was using converting DateTime value.
DateTimeFormatInfo ukDtfi = new CultureInfo(CultureInfo.CurrentCulture.ToString(), false).DateTimeFormat;
StartingDate = Convert.ToDateTime(System.Web.HttpContext.Current.Session["StartDate"].ToString(), ukDtfi);
I am using above code but its not working properly.
Currently I set ar-SA
culture in my system.
Try to solve your problem with this:
Let me clear some subjects first..
A
DateTime
instance does not have any timezone information and culture settings. It just have date and time values. Culture settings concept only applies when you get it's textual (string) representatiton.Since you use
ar-SA
culture, your string format is not a standard date and time format for that culture.And you can't parse this string with
ar-SA
culture because this culture usesص
as aAMDesignator
since it usesUmAlQuraCalendar
rather than aGregorianCalendar
.You can use
InvariantCulture
(which usesAM
as aAMDesignator
and usesGregorianCalendar
) instead withDateTime.ParseExact
method with specify it's format exactly.which in your case;