2

I return instances of an APEX Class in a JS remoting API.

public class OpportunityDetail {
     ...
     public Date closeDate;
     ...

The problem what is returned to my JavaScript client code is Date in the form:

1368057600000

When it should be:

2013-05-09

Any ideas how I could ensure that JS Remoting would return it in the format

2013-05-09
3

You could initialize a new Date in Javascript from the long millisecond format that you are getting back.

var myDate = new Date(1368057600000);
myDate.getMonth() + 1 + "-" + myDate.getDate() + "-" + myDate.getFullYear()
1

Maybe you could format the milliseconds to the date on the client side?

var d = new Date(1368057600000);
var day = d.getDay();
var month = d.getMonth() + 1;
var year = d.getFullYear();
if(day < 10)
    day = '0' + day;
if(month < 10)
    month = '0' + month;
var formattedDate = year + '-' + month + '-' + day;
alert(formattedDate);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.