My jquery function returning date in json format,so i want to know how to convert this into datetime formate "mm/dd/yyyy"
Asked
Active
Viewed 5,251 times
3 Answers
1
DateTime date1;
DateTime.TryParseExact(formCollection["date"], "MM/dd/yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out date1);
- it will not throw any exception.
- if there is wrong format, you can compare with
DateTime.MinValue
, that is it succesfully converted.

Adeel
- 19,075
- 4
- 46
- 60
0
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.

Community
- 1
- 1

ashish.chotalia
- 3,696
- 27
- 28
0
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.

Guffa
- 687,336
- 108
- 737
- 1,005