Can anyone tell me how to convert the date format to string format in JavaScript Remoting?
Below is my code

    global static theHRMS__Employee__c getEmployee() {    
Contact c=[select birthdate__c from contact where id=0039000001CoN3m];    
return c;   



                            function(result, event){    
                                if (event.status) {   
                                     Var bdate=result.birthdate__c ;     

The above code gives alert message like


But my actual birthdate is 22/11/1992

I dono how to convert the date to string ?


3 Answers 3


JavaScript not only doesn't handle apex dates well (they get adjusted to locale) because it only understands datetime, but its native datetime manipulation functions are pretty weak.

I throw momentjs (open library) into any org that uses remoting with dates...saves all kind of complexity.

Moment will format all your dates any way you want them, compare them properly (js won't with some ugly hacks!!) and do things like time zone adjustments to undo what Salesforce does via locale.


Try this : http://blogforce9.blogspot.fr/2013/02/handling-dates-in-visualforce-js.html

I did not test it, but it sounds a good solution. I faced the same problem before, what I did is to return String in my remote action and not date.


To convert a JavaScript date object into a string, simply omit the "new" keyword when instantiating the date object.

Use this: Date();. - returns typeof "string".

Do not use this: new Date();. - returns typeof "object".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .