现在有Opportunity表中,最近的更新日时计算与系统日付之间的时间如何差
Datetime sysDateTime = System.now();
String strSysDateTime = sysDateTime.format('YYYY-MM-dd HH:mm:ss');
system.debug('strSysDateTime>>>'+strSysDateTime);
List<Opportunity> oppList = [SELECT LastModifiedDate
FROM Opportunity
ORDER BY LastModifiedDate DESC];
Datetime lastModifiedDate = oppList.get(0).LastModifiedDate;
String strConvertedDate = lastModifiedDate.format('YYYY-MM-dd HH:mm:ss');
system.debug('strConvertedDate>>>'+strConvertedDate);
long fromDateTime = Datetime.ValueOf(strConvertedDate).getTime();
long toDateTime = Datetime.ValueOf(strSysDateTime).getTime();
Integer days = (Integer)((toDateTime - fromDateTime) / (1000 * 60 * 60 * 24));
system.debug('最终更新日和系统日付的天数差为>>>'+days);
Integer hours = (Integer)((toDateTime - fromDateTime) / (1000 * 60 * 60));
system.debug('最终更新日和系统日付的小时差为>>>'+hours);
Integer minutes = (Integer)((toDateTime - fromDateTime) / (1000 * 60));
system.debug('最终更新日和系统日付的分钟差为>>>'+minutes);
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。