diff --git a/snippets/convert-json-date.md b/snippets/convert-json-date.md new file mode 100644 index 000000000..3c0d276dc --- /dev/null +++ b/snippets/convert-json-date.md @@ -0,0 +1,14 @@ +### Convert Json Date + +Convert dates coming from ajax as json to readable format +Example: converts "/Date(1489525200000)/" to "15/2/2017" + + ```js +cconst JsonToDate = arr => + { + const dt = new Date(parseInt(arr.toString().substr(6))); + return dt.getDate() + '/' + dt.getMonth() + '/' + dt.getFullYear(); + }; + // JsonToDate(/Date(1489525200000)/) -> 15/2/2017 + ``` +