0
public class MyCustomController1
 {

public class studObjectwrap
     {public String D_ob{get;set;}}

@RemoteAction 
public static String createRecord(String jsonObjResult){  
//Some Code od Json Deserialization
Student__c st=new Student__c();
//Converting Date Into Salesforce Date Format i.e MM/DD/YYYY
          String strTest = sc.D_ob;
          String[] arrTest = strTest.split('-');
          String datetosend=arrTest[1]+'/'+arrTest[2]+'/'+arrTest[0];
          sc.D_ob=datetosend;
         //Parsed into Date
          st.DOB__c= date.parse(sc.D_ob);
}

@RemoteAction    
    public static Student__c fetchRecord()
    {
        Student__c student=[
                            SELECT DOB__c
                            FROM Student__c 
                            order by CreatedDate desc limit 1
                           ];
        System.debug(student);
        return student;
    }

//VisualForce Page

function fetchRecord() {     
         MyCustomController1.fetchRecord(handlefetchStudent); 
       }

function handlefetchStudent(result,event){
         if(event.type == 'exception') {
              alert(event.message);
          } else {
         console.log(result.DOB__c.toString());
          }

//but date stored as 1/1/2017 in salesforce org i want same date how to do it?

//Output on console=1483228800000

1 Answer 1

2

The field is being written out in epoch time (the number of millseconds since January 1st, 1970). To get it back to a normal date, use the Date constructor:

console.log(new Date(result.DOB__c));

You could have also avoided this issue by serializing the result into JSON before returning, and deserializing afterwards:

@RemoteAction public static String fetchRecord() {
    // ...
    return JSON.serialize(student);
}

// ... In JS
console.log(JSON.parse(result));
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.