How to get the time in the timezone of my Google Ads account?

Are you writing a Google Ads Script and trying to get time in the timezone of your account?

Big chance you encounter an issue with the timezone.

Here’s the thing:

When you create a new Date object in Javascript, it uses the local time of the computer it’s running on. In the case of Google Ads Scripts this is the Google servers that run our scripts, and these are in the America/Los_Angeles (Pacific time) zone.

If you want to create a Date object with the time in the timezone of your Google Ads account, you need to to use ‘ AdsApp.currentAccount().getTimeZone()’ .

Here’s an example to explain and show the difference:

function main() {

  // this logs the current time in the timezone of Google's server (America/Los_Angeles, Pacific time)
  var currentTime = new Date();
  Logger.log('The current timeat Google server is: ' + currentTime);  
 
  // and this this logs the time using your Google Ads account timezone
  var currentTimeAccount = getAccountCurrentDateTime();
  Logger.log('The current account time is: ' + currentTimeAccount);
}

//this function shows how to get the time in the timezone of the google ads account  
function getAccountCurrentDateTime() {
  Logger.log('The account time zone is: ' +  AdsApp.currentAccount().getTimeZone());
  return new Date(Utilities.formatDate(new Date(), AdsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
}

Happy scripting!

 

Join thousands of PPC geeks who already have access:

If the button above isn’t working for you, you can sign up here to get access.