You need to sign in to do that
Don't have an account?

System v/s Date
Hi Guys,
Â
We have two classes System and Datetime in apex. Both provides static now  method. I want to know what is difference between now method from System and Datetime class. I would also like to know broad idea of System class and when to use it?
Â
Â
Â
Thanks
Hello,
 Well as therotical difference between these two is that datetime.now() returnds time in GMT calaender format i.e. mm/dd/yyyy  hh:mm Period like this 9/22/2011ï»żÂ 5:00 AMï»ż but when you use System.now() it will retrurns the current datetime of your server in  standared format. This is the theoretical difference but i did't find this practicaly.
All Answers
Hello,
 Well as therotical difference between these two is that datetime.now() returnds time in GMT calaender format i.e. mm/dd/yyyy  hh:mm Period like this 9/22/2011ï»żÂ 5:00 AMï»ż but when you use System.now() it will retrurns the current datetime of your server in  standared format. This is the theoretical difference but i did't find this practicaly.
System.now returns the current date and time in the GMT time zone.
And Datetime.now returns the current Datetime based on a GMT calendar. For example:
datetime myDateTime = datetime.now();
The format of the returned datetime is: 'MM/DD/YYYY HH:MM PERIOD'ï»ż
Â
System class has various utility methods and one should use them while working with any of the following tasks.
Â
Hope that helps.
Â
Afzal
System.now() returns the same value as Datetime.now(): Â Â 2017-01-06 09:34:04
System.today() returns the same date as Date.today(): Â Â 2017-01-06 00:00:00
But System methods work faster! The difference is quit small, until you are calling these methods millions of times:
For Date.today(), the cost per invocation is about 4.43”s, whereas System.today() costs about 3.85”s per invocation, a difference of about ~15%.
For Datetime.now(), the cost per invocation is about 3.48”s, whereas System.now() costs about 2.97”s per invocation, a difference of ~17%.
Â