I have encounter an issue while working with datetime
in asp.net. While sending datetime string from an textbox to DateTime according to the Turkish Culture, the datetime
format is breaking.
For instance; i am sending these parameters on querystring -
?beginDate=02.01.2014&endDate=03.01.2014
, these parameters values appear like the following when passed ActionResult parameter -
beginDate = 01.02.2014, endDate = 03.01.2014
.
I tried a couple solution but problems still exists.
1)
protected void Application_Start()
{
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("tr-TR");
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("tr-TR");
}
2)
<globalization uiCulture="tr-TR" culture="tr-TR" />
3)
return Json(_db.GetList(Convert.ToDateTime(begin, new CultureInfo("tr-TR")), Convert.ToDateTime(end, new CultureInfo("tr-TR")))
4)
begin.Value.ToString("dd.mm.yyyy")
end.Value.ToString("dd.mm.yyyy")
Url
domain.com/Home/GetList?begin=02.01.2014&end=03.01.2014
GetList Method
public JsonResult GetList(DateTime? begin, DateTime? end)
{
return Json(_db.GetList(Convert.ToDateTime(begin, new CultureInfo("tr-TR")), Convert.ToDateTime(end, new CultureInfo("tr-TR")))
}