Returns the given date converted to UTC using the given timezone.
@param millis The date to convert
@param tz The timezone associated with the date
@return The given date converted using the given timezone
185316
public static long convertToUtc(long millis, String tz)
    {
        long ret = millis;
        if(tz != null && tz.length() > 0)
        {
            DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
            ret = dt.withZoneRetainFields(DateTimeZone.forID("UTC")).getMillis();
        }
        return ret;
    }
1219576
def to_utc(value, defaulttz=None):
    
    if defaulttz is None:
        defaulttz = tzlocal()
    return _convert(value, tzutc(), defaulttz)
369124
public static TimeZone timeZoneForName(String tzString) {
        // This is a horrible hack since there is no easier way to get a timezone
        // only if the string is recognized as a timezone.
        // The TimeZone.getTimeZone javadoc says the following:
        //   Returns:
        //       the specified TimeZone, or the GMT zone if the given ID cannot be
        //       understood.
        TimeZone tz = TimeZone.getTimeZone(tzString);
        if (tz.hasSameRules(BOGUS_TIMEZONE)) {
            // see if the user really was asking for GMT because if
            // TimeZone.getTimeZone can't recognize tzString, then that is what it
            // will return.
            Matcher m = UTC_TZID.matcher(tzString);
            if (m.matches()) {
                return TimeUtils.utcTimezone();
            }
            // unrecognizable timezone
            return null;
        }
        return tz;
    }
1068764
public static String getDisplayedTimezone(long startMillis, String localTimezone,
                                              String eventTimezone) {
        String tzDisplay = null;
        if (!TextUtils.equals(localTimezone, eventTimezone)) {
            // Figure out if this is in DST
            TimeZone tz = TimeZone.getTimeZone(localTimezone);
            if (tz == null || tz.getID().equals("GMT")) {
                tzDisplay = localTimezone;
            } else {
                Time startTime = new Time(localTimezone);
                startTime.set(startMillis);
                tzDisplay = tz.getDisplayName(startTime.isDst != 0, TimeZone.SHORT);
            }
        }
        return tzDisplay;
    }
1007761
def format_as_utc(self, value):
        """"""
        if isinstance(value, datetime.datetime):
            if value.tzinfo is not None:
                value = value.astimezone(pytz.UTC)
            value = value.replace(microsecond=0)
        return value.isoformat().replace('+00:00', 'Z')
737599
protected static function getTimezoneObject($tz)
    {
        // If the time zone object is not set, attempt to build it.
        if (!($tz instanceof \DateTimeZone)) {
            if ($tz === null) {
                $tz = static::useServerDefaultTimezone() ? self::$stz : self::$gmt;
            } elseif (is_string($tz)) {
                $tz = new \DateTimeZone($tz);
            } elseif ($tz === static::TZ_LOCALE) {
                $config = Ioc::getConfig();
                $tz     = $config->get('system.timezone');
                $tz     = new \DateTimeZone($tz);
            }
        }

        return $tz;
    }
615281
def ensure_timezone(dt, tz=None):
    
    if dt.tzinfo is None:
        return dt.replace(tzinfo=tz or tzlocal())
    else:
        return dt
47079
def to_utc(self, dt):
        """"""
        if dt.tzinfo is None:
            return dt.replace(tzinfo=self.utc)
        return dt.astimezone(self.utc)
577196
public static String isoDateTime(final Date val, final TimeZone tz) {
    synchronized (isoDateTimeTZFormat) {
      isoDateTimeTZFormat.setTimeZone(tz);
      return isoDateTimeTZFormat.format(val);
    }
  }
1187858
public static final Date utc2date(Long time) {

        // don't accept negative values
        if (time == null || time < 0) return null;
        
        // add the timezone offset
        time += timezoneOffsetMillis(new Date(time));

        return new Date(time);
    }
754548
def timezone(self, tz):
        
        self.data['resolving'].update(
            timezone=tz,
            time_show_zone=True)
564833
def in_timezone(self, tz):  # type: (Union[str, Timezone]) -> DateTime
        
        tz = pendulum._safe_timezone(tz)

        return tz.convert(self, dst_rule=pendulum.POST_TRANSITION)
1368281
public String toISO8601Date(long utcEpochMillis, @Nullable DateTimeZone dtz) {
		return toISO8601Date(new DateTime(utcEpochMillis, dtz), dtz);
	}
436359
public java.util.Date getDateWithZone(ZoneId timezone) {
        LocalDate pickerDate = parentDatePicker.getDate();
        if (pickerDate == null || timezone == null) {
            return null;
        }
        Instant instant = pickerDate.atStartOfDay(timezone).toInstant();
        // for backport: java.util.Date javaUtilDate = DateTimeUtils.toDate(instant);
        // for java.time: java.util.Date javaUtilDate = java.util.Date.from(instant);
        // This function was created to be compatible with both libraries.
        java.util.Date javaUtilDate = getJavaUtilDateFromInstant(instant);
        return javaUtilDate;
    }
190691
public static ZoneId toZoneId(TimeZone tz) {
        // Android-changed: don't support "old mapping"
        return ZoneId.of(tz.getID(), ZoneId.SHORT_IDS);
    }
707798
public static String fromUnixtime(long unixtime, String format, TimeZone tz) {
		SimpleDateFormat formatter = FORMATTER_CACHE.get(format);
		formatter.setTimeZone(tz);
		Date date = new Date(unixtime * 1000);
		try {
			return formatter.format(date);
		} catch (Exception e) {
			LOG.error("Exception when formatting.", e);
			return null;
		}
	}
1071298
def _get_timezone(self, tz):
        
        # special Local timezone
        if tz == "Local":
            try:
                return tzlocal.get_localzone()
            except pytz.UnknownTimeZoneError:
                return "?"

        # we can use a country code to get tz
        # FIXME this is broken for multi-timezone countries eg US
        # for now we just grab the first one
        if len(tz) == 2:
            try:
                zones = pytz.country_timezones(tz)
            except KeyError:
                return "?"
            tz = zones[0]

        # get the timezone
        try:
            zone = pytz.timezone(tz)
        except pytz.UnknownTimeZoneError:
            return "?"
        return zone