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%.