Monday, 7 August 2017

How can I format a json date in dd/mm/yy format in javascript?

How can I format a json date in dd/mm/yy format in javascript?

Description:

In this example we explain that how to format a JSON date in dd/mm/yy format using JavaScript. Or how to convert the json date to dd/mm/yy format using JavaScript. Or how to format json string date to dd/mm/yy format using JavaScript.

Suppose I have a json date string like \/Date(1334514600000)\/ in my json response so how to convert this response text to date format like dd/mm/yy format using JavaScript.

Below is the code that demonstrate how to convert json response date to dd/mm/yy date format using JavaScript.

Code:
  
var dateString = "\/Date(1334514600000)\/".substr(6);
var currentTime = new Date(parseInt(dateString ));
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var date = day + "/" + month + "/" + year;
alert(date);



0 comments:

Post a Comment