[SalesForce] Date Format to String Format in JavaScript Remoting

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

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

My VFP:

Visualforce.remoting.Manager.invokeAction(     
                            '{!$RemoteAction.NewUIEmployeeContr.getEmployee}',    

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

The above code gives alert message like

731808000000

But my actual birthdate is 22/11/1992

I dono how to convert the date to string ?

Best Answer

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.

Related Topic