Convert Json Date to Javascript Date Format

Convert Json Date to Javascript Date Format

Convert json date to javascript date object

Before convert json date to javascript date object we need to create json serialized .net datetime using System.Web.Script.Serialization namespace.

Output“\/Date(1513276200000)\/”

Now we have got the above Json date string using .net JavaScriptSerializer.

Convert json date to javascript date object

JSON dates come in a format that isn’t directly convertable to Javascript date objects (e.g. “\/Date(1513276200000)\/” ). This can cause a bit of headache, but there is a very simple way to convert this to a native date object.

After stripping off the initial “/Date” part using substr, parseInt will return only the integers and ignore the trailing “/”. The result is an integer value that can be used in the native javascript Date constructor. Find the below source code to convert json date to date in javascript :-

Output15/12/2017

Did you find this post useful? I hope you liked this article. Please share with me your valuable suggestions and feedback.

LEAVE A REPLY

Please enter your comment!
Please enter your name here