How to find minutes, seconds and Milliseconds difference between two datetime in Salesforce?

getTime() in Salesforce is used to get milliseconds from a Datetime.

Sample Code:

DateTime maxTime = System.now().addMinutes(5);
DateTime minTime = System.now();
system.debug('Milliseconds Difference is ' + (maxTime.getTime() - minTime.getTime()));
system.debug('Seconds Difference is ' + (maxTime.getTime() - minTime.getTime()) / 1000);
system.debug('Minustes Difference is ' + (maxTime.getTime() - minTime.getTime()) / 60000);

Output:



Cheers!!!

No comments:

Post a Comment