com.google.api.ads.dfp.axis.utils.v201206
Class DateTimes

java.lang.Object
  extended by com.google.api.ads.dfp.axis.utils.v201206.DateTimes

public final class DateTimes
extends Object

A utility class for handling DateTime objects.

Author:
Adam Rogal

Method Summary
static Calendar toCalendar(DateTime dateTime)
          Gets a calendar for a DateTime using the default locale, i.e.
static Calendar toCalendar(DateTime dateTime, Locale locale)
          Gets a calendar for a DateTime in the supplied locale.
static DateTime toDateTime(Calendar calendar)
          Converts a Calendar object to an API date time preserving the time zone.
static DateTime toDateTime(org.joda.time.DateTime dateTime)
          Converts a DateTime object to an API date time preserving the time zone.
static org.joda.time.DateTime toDateTime(DateTime dateTime)
          Converts an API date time to a DateTime preserving the time zone.
static DateTime toDateTime(org.joda.time.Instant instant, String timeZoneId)
          Converts an Instant object to an API date time in the time zone supplied.
static DateTime toDateTime(String dateTime, String timeZoneId)
          Converts a string in the form of yyyy-MM-dd'T'HH:mm:ss to an API date time in the time zone supplied.
static String toString(DateTime dateTime)
          Returns string representation of this date time.
static String toStringWithZone(DateTime dateTime, String newZoneId)
          Returns string representation of this date time with a different time zone, preserving the millisecond instant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toDateTime

public static DateTime toDateTime(Calendar calendar)
Converts a Calendar object to an API date time preserving the time zone.


toDateTime

public static DateTime toDateTime(org.joda.time.Instant instant,
                                  String timeZoneId)
Converts an Instant object to an API date time in the time zone supplied.


toDateTime

public static DateTime toDateTime(org.joda.time.DateTime dateTime)
Converts a DateTime object to an API date time preserving the time zone.


toDateTime

public static DateTime toDateTime(String dateTime,
                                  String timeZoneId)
Converts a string in the form of yyyy-MM-dd'T'HH:mm:ss to an API date time in the time zone supplied.


toDateTime

public static org.joda.time.DateTime toDateTime(DateTime dateTime)
Converts an API date time to a DateTime preserving the time zone.


toCalendar

public static Calendar toCalendar(DateTime dateTime)
Gets a calendar for a DateTime using the default locale, i.e. Locale.getDefault().


toCalendar

public static Calendar toCalendar(DateTime dateTime,
                                  Locale locale)
Gets a calendar for a DateTime in the supplied locale.


toString

public static String toString(DateTime dateTime)
Returns string representation of this date time. The string representation does not include the time zone since using date times for filtering does not use the time zone. If you need to convert the date time into another time zone before filtering on it, please use toStringWithZone(DateTime, String) instead.

Parameters:
dateTime - the date time to stringify
Returns:
a string representation of the DateTime in yyyy-MM-dd'T'HH:mm:ss

toStringWithZone

public static String toStringWithZone(DateTime dateTime,
                                      String newZoneId)
Returns string representation of this date time with a different time zone, preserving the millisecond instant.

This method is useful for finding the local time in another time zone, especially for filtering.

For example, if this date time holds 12:30 in Europe/London, the result from this method with Europe/Paris would be 13:30. You may also want to use this with your network's time zone, i.e.

 String timeZoneId = networkService.getCurrentNetwork().getTimeZone();
 String statementPart =
     "startDateTime > "
         + DateTimes.toString(apiDateTime, timeZoneId);
 //...
 statementBuilder.where(statementPart);
 
This method is in the same style of DateTime.withZone(org.joda.time.DateTimeZone).

Parameters:
dateTime - the date time to stringify into a new time zone
newZoneId - the time zone ID of the new zone
Returns:
a string representation of the DateTime in yyyy-MM-dd'T'HH:mm:ss


Copyright © 2012. All Rights Reserved.