1

I'm new to Salesforce development and not sure why when I read a database column as string my result in debug log is:

01/06/2016 10:09 AM

while when i change it to DateTime it becomes:

2016-01-06 15:09:00

Why is there difference in the two? Any insights will be helpful. Here is my code:

String lastRunTime = myFeature.getAttributeValue('MyDate');
DateTime testDate = DateTime.parse(lastRunTime);
System.Debug('----------------------------------------------' + testDate);
System.Debug('----------------------------------------------' + lastRunTime);
1
  • What is myFeature? I'm guessing an Dom.XmlNode?
    – sfdcfox
    Jan 6, 2016 at 20:20

1 Answer 1

1

You are having issues with time zone conversion. Try using Datetime.newInstanceGmt to get around them.

String lastRunTime = '01/06/2016';
Datetime lastRun = Datetime.parse(lastRunTime);
Datetime lastRunGmt = Datetime.newInstanceGmt(lastRun.date(), lastRun.time());

For me these result in:

lastRun: 2016-01-06 17:09:00
lastRunGmt: 2016-01-06 10:09:00

You must log in to answer this question.

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