I have string like this:
"/Date(1388521800000)/"
How would I convert it to "YYYY-MM-DD"?
I have string like this:
"/Date(1388521800000)/"
How would I convert it to "YYYY-MM-DD"?
If the String always looks the same I would parse it like this:
String date = "/Date(1388521800000)/";
String stamp;
stamp = date.substring(date.indexOf("(")+1, date.indexOf(")"));
you can use this function to parse such date.
function fnParseDate(dateString)
{
if (typeof dateString == 'object' && dateString instanceof Date) // It's already a JS Object (Of Date Type)
return dateString; // No need to do any parsing. Return the original value.
if (dateString.indexOf('/Date(') == 0) //Format: /Date(1320259705710)/
return new Date(parseInt(dateString.substr(6), 10));
alert('Given date is no properly formatted: ' + dateString);
return new Date(); //Default value!
}
var sDate = "/Date(1388521800000)/";
var date = new Date(sDate.match(/\/Date\(([0-9]+)\)\//)[1]|0);
var formattedDate = date.getFullYear() + "-"+
(date.getMonth()<9?"0"+(date.getMonth()+1):date.getMonth()+1)+"-"+
(date.getDate()<10?"0"+date.getDate():date.getDate());