March 3, 2011

Convert JSON Date to Standard Date Format

Many peoples asked about JSON date conversion into Javascript code or Jquery
Code. The method is very simple and easy. When ever you insert Date into
database using Json and when you retrieve that date from database its in Json
Format which is some thing like that:

My input Date is : 14/2/2011 (for example)
My output Date is : /Date(1297246301973)/ (for example)

So here problems create when u update that date into database again its cause error.
Here's is simple code to formulate the actual date as you inserted before

var date = /Date(1297246301973)/;
var parsedDate = new Date(parseInt(date.substr(6)));
var newDate = new Date(parsedDate);

var getMonth = newDate.getMonth();
var getDay = newDate.getDay();
var getYear = newDate.getYear();

var standardDate = getMonth + '/' + getDay + '/' + getYear;

Now you got your date according to you format....:)