function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Francesco SciutoFrancesco Sciuto 

Understanding GetTime() function

Accordign to Salesforce documentation the GetTime() function "Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object.". Take into account that I am in GMT+1 if I use:

DateTime.newInstance(1970, 1, 1).GetTime();

I get a value of -3600000 milliseconds, meaning -1 hour. I was actually expecting +1 hour since I am in GMT +1, can anybody explain that? The only logic I can find about -1 hour is that when in GMT+1 was January 1, 1970, 00:00:00 in GMT it was still January 1, 1969, 23:00:00 GMT.

This function is really important for a token generation function I am building so I want to be sure I following a correct reasoning. Thanks
NagendraNagendra (Salesforce Developers) 
Hi Francesco,

This is known as a "Unix Timestamp" (number of milliseconds since January 1st, 1970, 00:00:00 GMT). In Apex Code, you can use DateTime.newInstance(unixTimestamp) to return a DateTime that contains the formatted date/time value. In JavaScript, use new Date(unitTimestamp) to get the same result. To convert back, in Apex Code, use myDate.getTime(), and in JavaScript, use the same function: myDate.getTime().

Please let us know if this helps.

Regards,
Nagendra.