Is this the right way of getting the Timezone?

1,002 views
Skip to first unread message

Oliver

unread,
Aug 30, 2012, 4:32:04 PM8/30/12
to adwor...@googlegroups.com
Assume the timezone of my account, as returned by an Account Report, is (GMT+00:00) London.

I need to use a Service object in my case and I use the ManagedCustomerService object to get the timezone (instead of an Account Report).

My code does this:

selector.setFields(new String[]{"DateTimeZone"});
ManagedCustomerPage page = managedCustomerService.get(selector);
for (ManagedCustomer customer : page.getEntries()) {
   System.out.println(customer.getDateTimeZone());
}

The output of this code is Europe/London and not (GMT+00:00) London (as given by the report).

Am I using the ManagedCustomerService wrongly?  Is there anyway to get the timezone via the Service object to look like the one we get from the report?

Thanks

Oliver

Jason Stedman

unread,
Aug 31, 2012, 6:59:49 AM8/31/12
to adwor...@googlegroups.com
Unfortunately the timezone offset is not available from the api, probably due to timezone offsets being subject to change outside control of Google.

You can map from the "POSIX" timezone name to the textual name component returned in the report by using the data from the table on this page:

https://developers.google.com/adwords/api/docs/appendix/timezones

I hoped to find this mapping in the ConstantDataService, but unfortunately it has not been implemented there yet.

Oliver

unread,
Aug 31, 2012, 7:03:43 AM8/31/12
to adwor...@googlegroups.com
Thanks Jason.  I actually just wrote a question about timezones not being available via ConstantDataService!

However, the POSIX mapping in my particular case will map Europe/London to London and not (GMT+00:00) London, so even that won't help.  I need to be able to get the GMT offset of the timezone.

I guess my only option is the adhoc report then?

Oliver

Stefan Podkowinski

unread,
Aug 31, 2012, 8:47:44 AM8/31/12
to adwor...@googlegroups.com
Why not just use the java.util.TimeZone class to calculate the gmt offset?

TimeZone timeZoneDE = TimeZone.getTimeZone("Europe/London");
int utcoffset = timeZoneDE.getRawOffset();

Oliver

unread,
Aug 31, 2012, 9:10:03 AM8/31/12
to adwor...@googlegroups.com
Thanks. The offset value I get for a city like 'Sydney' is something like 72000000.  I'll get my developer to look into this class in more details to see if we can work it out.

Kevin Winter

unread,
Sep 5, 2012, 11:30:08 AM9/5/12
to adwor...@googlegroups.com
Hi Oliver,
  No, you are using this service correctly.  The difference is caused by the implementation of reports versus the SOAP api.  They read from different backend systems with different filter in place.

When working with dates and times, I cannot recommend the java library JodaTime highly enough.  The DateTimeZone object has multiple factory methods to load IDs in a variety of formats:

Of note is the ability to translate from offset hours (as a signed integer) to a timezone.

It even accepts a java DateTime object, which you can get for the long string, like so:

TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");

We recommend using JodaTime to deal with the intricacies of time zones.

- Kevin Winter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages