MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / astimezone

Method astimezone

tools/python-3.11.9-amd64/Lib/datetime.py:1968–1991  ·  view source on GitHub ↗
(self, tz=None)

Source from the content-addressed store, hash-verified

1966 return timezone(timedelta(seconds=gmtoff), zone)
1967
1968 def astimezone(self, tz=None):
1969 if tz is None:
1970 tz = self._local_timezone()
1971 elif not isinstance(tz, tzinfo):
1972 raise TypeError("tz argument must be an instance of tzinfo")
1973
1974 mytz = self.tzinfo
1975 if mytz is None:
1976 mytz = self._local_timezone()
1977 myoffset = mytz.utcoffset(self)
1978 else:
1979 myoffset = mytz.utcoffset(self)
1980 if myoffset is None:
1981 mytz = self.replace(tzinfo=None)._local_timezone()
1982 myoffset = mytz.utcoffset(self)
1983
1984 if tz is mytz:
1985 return self
1986
1987 # Convert self to UTC, and attach the new time zone object.
1988 utc = (self - myoffset).replace(tzinfo=tz)
1989
1990 # Convert from UTC to tz's local time.
1991 return tz.fromutc(utc)
1992
1993 # Ways to produce a string.
1994

Callers 4

Time2InternaldateFunction · 0.80
formatdateFunction · 0.80
localtimeFunction · 0.80
file_mtimeFunction · 0.80

Calls 5

_local_timezoneMethod · 0.95
replaceMethod · 0.95
utcoffsetMethod · 0.45
replaceMethod · 0.45
fromutcMethod · 0.45

Tested by

no test coverage detected