[SalesForce] How to Update a datetime field with current date time in VF page

I need to update a datetime field with current date time in VF page using JavaScript.Currently my code is like this :

        var newRecords = [];
        var a = new sforce.SObject("myObj__c");
        a.id ="{!myObj.Id}";
        var today = new Date();
        a.Last_Time_Executed__c = sforce.internal.dateTimeToString(today);
        newRecords.push(a);
        result = sforce.connection.update(newRecords);

But it shows this error:

{faultcode:'soapenv:Client',
faultstring:''2013-11-27T13:04:46.539+05.5:30' is not a valid value
for the type xsd:dateTime', }

Best Answer

This worked:

        var newRecords = [];
        var a = new sforce.SObject("MyObj__c");
        a.id ="{!SOQL_Report__c.Id}";
        a.Last_Time_Executed__c = new Date().toISOString();
        newRecords.push(a);
        result = sforce.connection.update(newRecords);
Related Topic