def datetime_to_ms(d):
    """Convert a Python datetime object to a millisecond epoch (UTC) time value."""
    try:
        millisecond = d.microsecond // 1000
        return calendar.timegm(_add_tzone(d).utctimetuple()) * 1000 + millisecond
    except AttributeError:
        raise TypeError('expect Python datetime object, not %s' % type(d))