I want to convert a JSON formatted Date to a formatted string.
I got this date format I want to convert to a .Net DateT : "/Date(1480593300000)/"
public JsonResult DateFormat(string date)
{
DateTime temp = new DateTime(int.Parse(date.Substring(6, 13)));
string res = temp.ToString("g", Thread.CurrentThread.CurrentCulture);
return Json(res, JsonRequestBehavior.AllowGet);
}
This is how I tried to do it, I get 02/01/0001 17:07.
So my question is, is there a better, more efficient way to do it ?
Also, is there a way in C# to display this specific format, depending on the culture : fr-FR : 31/12 17:07 en-US : 12/31 5:07pm ? I could do it manually but an equivalent to the
DateTime.ToString("g", IFormatProvider)
for this format would be perfect.