Snippets Collections
from time import gmtime, strftime

 strftime("%Y-%m-%d %H:%M:%S", gmtime())
'2009-01-05 22:14:39'

Integer year = 2021, mon=02, day=12, hour=23, min=50;

Datetime dtGMT = Datetime.newInstanceGMT(year, mon, day, hour, min, 0);

String exTimezone = 'America/Los_Angeles';
String dateTimeForamat = 'yyyy-MM-dd HH:mm:ssz';
String schedulerFormat = 'mm:HH:dd:MM:yyyy';
String crnTemplate = '0 {0} {1} {2} {3} ? {4}';

String localFromatted = dtGMT.format(dateTimeForamat, UserInfo.getTimeZone().getId());
String exFormatted = dtGMT.format(dateTimeForamat, exTimezone);

Datetime localDTValueGMT = Datetime.valueOfGMT(localFromatted);
Datetime exDTVaueGMT = Datetime.valueOfGMT(exFormatted);

Integer minDiff = (Integer)(localDTValueGMT.getTime() - exDTVaueGMT.getTime())/60000;

Datetime scheduleDTGMT = dtGMT.addMinutes(minDiff + 15);

String schFormmated = scheduleDTGMT.formatGMT(schedulerFormat);

String cronExp = String.format(crnTemplate, schFormmated.split(':'));

System.debug('dtGMT : ' + JSON.serialize(dtGMT));
System.debug('localDTValueGMT : ' + JSON.serialize(localDTValueGMT));
System.debug('exDTVaueGMT : ' + JSON.serialize(exDTVaueGMT));
System.debug('scheduleDTGMT : ' + JSON.serialize(scheduleDTGMT));
System.debug('cronExp: ' + cronExp);
star

Thu Dec 31 2020 16:38:29 GMT+0000 (UTC)

#python #datetime
star

Wed Dec 16 2020 17:34:22 GMT+0000 (UTC)

#apex #datetime

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension