Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
How can I convert a Json DateTime string to normal dateformat?

I get the Json DateTime as



Datestamp": "2014-10-05T00:00:00".


Here Datestamp is the column name.

I need to write a function using Javascript. This functing has two parameter one is this 'Datestamp', another is 'Dateformate'. I need to convert this 'Datastamp' as given date 'Dateformate' and function will return this DateTime.

Please help me by providing this code.

Remind that my Datestamp parameter will always get this type of string foramte "2014-10-05T00:00:00".
Posted

 
Share this answer
 
Date objects are created with new Date().

For example.
var date = new Date(Datestamp);
 
Share this answer
 
var date = new Date(parseInt(Datestamp.substr(10)));
here the substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end. The resulting number is passed into the Date constructor.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900