Reputation: 1
My jquery function returning date in json format,so i want to know how to convert this into datetime formate "mm/dd/yyyy"
Upvotes: 0
Views: 5379
Reputation: 19228
DateTime date1;
DateTime.TryParseExact(formCollection["date"], "MM/dd/yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out date1);
DateTime.MinValue
, that is it succesfully converted.Upvotes: 2
Reputation: 700342
There is no date data type in JSON, so what you have is a date formatted as a string. Use the ParseExact
method to parse the string into a DateTime
value.
Then you can use the ToString
method or String.Format
method using the pattern MM'/'dd'/'yyyy
to format the DateTime
value into a string.
Upvotes: 0
Reputation: 3746
How do I format a Microsoft JSON date?
You can use this to get a date from json:
var date = eval(jsonDate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
and then you can use JavaScript Date Format script (1.2 KB when minified and gzipped) to display it as you want.
Upvotes: 0