ANS-1015 · SUITESCRIPT DEVELOPMENT

Why Does date.getTime() Return the Same Value Regardless of Timezone?

Understand how JavaScript's getTime() method calculates time based on a universal reference point, ensuring consistent results across different geographical locations.

Short answer

The date.getTime() method consistently returns the number of milliseconds elapsed since January 1st, 1970, Greenwich Mean Time (GMT). This universal reference point ensures that the returned value remains identical regardless of the local timezone where the function is executed, providing a standardized timestamp for all operations.

Scenario

Users may observe that the date.getTime() function in JavaScript yields an identical numerical output, even when executed in different timezones. This behavior can lead to confusion if the expectation is for the value to reflect local time differences.

Solution

The date.getTime() method is designed to return the number of milliseconds that have passed since January 1st, 1970, Greenwich Mean Time (GMT). Because this reference point is universal, the value returned by date.getTime() will always be the same, irrespective of the local timezone where the code is executed. For example, executing now.getTime() in California will produce the exact same value as executing now.getTime() in Paris.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant