Skip to main content
added 3 characters in body
Source Link
Ideasforce
  • 1.2k
  • 2
  • 7
  • 18

Note the time needs to be transformed to GMT based on the timezone:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
String[] dateSplit = dateTimeSplit[0].split('-');
String[] timeSplit = dateTimeSplit[1].split(':'); //you will have to write a function that converts the time to GMT based on the dateTimeSplit[2] literal
Datetime dt = DateTime.newInstanceGmt( Integer.valueOf(dateSplit[0]), Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]), Integer.valueOf(timeSplit[0]), Integer.valueOf(timeSplit[1]), 0);
system.debug('dt'+dt);
ts.Start_Time__c = dt;

See DateTime newInstanceGmt method

Note the time needs to be transformed to GMT based on the timezone:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
String[] dateSplit = dateTimeSplit[0].split('-');
String[] timeSplit = dateTimeSplit[1].split(':'); //you will have to write a function that converts the time to GMT based on the dateTimeSplit[2] literal
Datetime dt = DateTime.newInstanceGmt( Integer.valueOf(dateSplit[0]), Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]), Integer.valueOf(timeSplit[0]), Integer.valueOf(timeSplit[1]));
system.debug('dt'+dt);
ts.Start_Time__c = dt;

See DateTime newInstanceGmt method

Note the time needs to be transformed to GMT based on the timezone:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
String[] dateSplit = dateTimeSplit[0].split('-');
String[] timeSplit = dateTimeSplit[1].split(':'); //you will have to write a function that converts the time to GMT based on the dateTimeSplit[2] literal
Datetime dt = DateTime.newInstanceGmt( Integer.valueOf(dateSplit[0]), Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]), Integer.valueOf(timeSplit[0]), Integer.valueOf(timeSplit[1]), 0);
system.debug('dt'+dt);
ts.Start_Time__c = dt;

See DateTime newInstanceGmt method

added 70 characters in body
Source Link
Ideasforce
  • 1.2k
  • 2
  • 7
  • 18

Assuming all your inputs are in either CDT or CST you could doNote the time needs to be transformed to GMT based on the timezone:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
DatetimeString[] dtdateSplit = datetimedateTimeSplit[0].parsesplit(dateTimeSplit[0] +'-');
String[] 'T'timeSplit += dateTimeSplit[1].split(':'); +//you will have to write a function that converts the time to GMT based on the dateTimeSplit[2] ==literal
Datetime 'CST'dt ?= '-06:00'DateTime.newInstanceGmt( :Integer.valueOf(dateSplit[0]), '-05:00'Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]), Integer.valueOf(timeSplit[0]), Integer.valueOf(timeSplit[1]));
system.debug('dt'+dt);
ts.Start_Time__c = dt;

Note the timezone determines the appended '-06:00' or '-05:00' if you need support for other timezones you could write an auxiliar method to calculate the appended difference to GMT.

Here you can see the format for DateTime literals.See DateTime newInstanceGmt method

Assuming all your inputs are in either CDT or CST you could do:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
Datetime dt = datetime.parse(dateTimeSplit[0] + 'T' + dateTimeSplit[1] + dateTimeSplit[2] == 'CST' ? '-06:00' : '-05:00');
system.debug('dt'+dt);
ts.Start_Time__c = dt;

Note the timezone determines the appended '-06:00' or '-05:00' if you need support for other timezones you could write an auxiliar method to calculate the appended difference to GMT.

Here you can see the format for DateTime literals.

Note the time needs to be transformed to GMT based on the timezone:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
String[] dateSplit = dateTimeSplit[0].split('-');
String[] timeSplit = dateTimeSplit[1].split(':'); //you will have to write a function that converts the time to GMT based on the dateTimeSplit[2] literal
Datetime dt = DateTime.newInstanceGmt( Integer.valueOf(dateSplit[0]), Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]), Integer.valueOf(timeSplit[0]), Integer.valueOf(timeSplit[1]));
system.debug('dt'+dt);
ts.Start_Time__c = dt;

See DateTime newInstanceGmt method

Source Link
Ideasforce
  • 1.2k
  • 2
  • 7
  • 18

Assuming all your inputs are in either CDT or CST you could do:

String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart')
                .getValue()).split(' ');
Datetime dt = datetime.parse(dateTimeSplit[0] + 'T' + dateTimeSplit[1] + dateTimeSplit[2] == 'CST' ? '-06:00' : '-05:00');
system.debug('dt'+dt);
ts.Start_Time__c = dt;

Note the timezone determines the appended '-06:00' or '-05:00' if you need support for other timezones you could write an auxiliar method to calculate the appended difference to GMT.

Here you can see the format for DateTime literals.