You need to sign in to do that
Don't have an account?
Francesco 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
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
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.