1

The company default time zone is GMT (+00:00), and a date sent using the API is coming through like this:

09:16:37.032 (32355740)|USER_DEBUG|[17]|DEBUG|Date/Time: 2014-06-19T10:16:00.977

It arrives as a string in an HTTP GET request, the following apex code runs to convert it to the only datetime format it seems to accept:

relatedRecord.Receipt_Received_At__c = Datetime.valueOf(g_datetime.substring(0, 19).replace('T', ' '));
update relatedRecord;

But then when I go to view it in the saved record detail page, it is showing 11:16, not 10:16. I've tried changing valueOf() to valueOfGmt() but it doesn't change it. Why is the date saving as GMT+01:00?

  • I think you are experiencing day light saving if this is one our mismatch – highfive Jun 19 '14 at 9:39
  • What do you mean by we are experiencing it? The clocks went forward an hour earlier in the year, but SF kept itself correct and it saves Datetime.now() as the correct time, so why does it reformat this perfectly valid date? – Adam Jun 19 '14 at 9:41
  • what is the timezone of the user your are viewing the record with? – Guy Clairbois Jun 19 '14 at 9:42
  • not much sure, sometimes this link may help you help.salesforce.com/… – highfive Jun 19 '14 at 9:44
  • GMT+01:00, British Summer Time. I tried setting this to GMT but now everything is an hour behind where it should be. Regardless of what I set the company time zone to, the datetime that comes back via the URL is ALWAYS formatted an hour ahead of the datetime on salesforce. – Adam Jun 19 '14 at 9:45
1

I believe the issue is that your date is being sent through without knowledge of the timezone it is working in and so is assuming GMT and then displaying it as BST (correctly given we are in BST currently). Salesforce stores all times in GMT and then using your locale determines the correct display and return values.

Try adding a timezone designator (such as +01:00) to your string to get the system to recognise it is being sent in as BST and so should save internally as GMT (1 hour behind). The system generating your string will need to handle this going forward though by correctly parameterizing the datetimes for use in the future.

| improve this answer | |

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.