Sample Code
DateTime startDate = DateTime.now();
DateTime endDate = DateTime.now().addDays(2).addHours(5);
map<String, Integer > diffMap = new Map<String, Integer>();
Long startDateTime = startDate.getTime();
Long endDateTime = endDate.getTime();
Decimal sdiffMilliSecs = Decimal.valueOf(endDateTime - startDateTime);
Decimal sdDays = sdiffMilliSecs/1000/60/60/24;
Integer siDays = Integer.valueOf(math.floor(sdDays));
Decimal sremainderDays = sdDays- siDays;
Decimal sdHours = sremainderDays * 24;
Integer siHours = Integer.valueOf(math.floor(sdHours));
Decimal sremainderHours = sdHours - siHours;
Decimal sdMinutes = sremainderHours * 60;
Integer siMinutes = Integer.valueOf(math.floor(sdMinutes));
Decimal sremainderMinutes = sdMinutes - siMinutes;
diffMap.put('Days', siDays);
diffMap.put('Hours', siHours);
diffMap.put('Minutes', siMinutes);
System.debug('diffMap ==> '+diffMap);
No comments:
Post a Comment