Skip to content

Instantly share code, notes, and snippets.

@rogiervandenberg
Created November 18, 2015 11:05
Show Gist options
  • Save rogiervandenberg/dd6f09a26a493243042a to your computer and use it in GitHub Desktop.
Save rogiervandenberg/dd6f09a26a493243042a to your computer and use it in GitHub Desktop.
Returns a timestamp corrected for the current timezone, instead of getting the UTC timezone. This can be useful for tracking timed-events in the perception of a user/visitor of your application/website in e.g. Google Tag Manager.
function getLocalTimeStamp () {
var currentDate = new Date();
var currentTime = currentDate.getTime();
var localOffset = (-1) * currentDate.getTimezoneOffset() * 60000;
var stamp = Math.round(new Date(currentTime + localOffset).getTime() / 1000);
return stamp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment