Python datetime.tzinfo 模块,fromutc() 实例源码

我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用datetime.tzinfo.fromutc()

项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:epg-dk.bundle    作者:ukdtom    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def fromtimestamp(timestamp, tz=None):
        """Return the local date and time corresponding to the POSIX timestamp.

        Same as is returned by time.time(). If optional argument tz is None or
        not specified, the timestamp is converted to the platform's local date
        and time, and the returned datetime object is naive.

        Else tz must be an instance of a class tzinfo subclass, and the
        timestamp is converted to tz's time zone. In this case the result is
        equivalent to
        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).

        fromtimestamp() may raise ValueError, if the timestamp is out of the
        range of values supported by the platform C localtime() or gmtime()
        functions. It's common for this to be restricted to years in 1970
        through 2038. Note that on non-POSIX systems that include leap seconds
        in their notion of a timestamp, leap seconds are ignored by
        fromtimestamp(), and then it's possible to have two timestamps
        differing by a second that yield identical datetime objects.

        See also utcfromtimestamp().
        """
项目:start    作者:argeweb    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def fromtimestamp(timestamp, tz=None):
        """Return the local date and time corresponding to the POSIX timestamp.

        Same as is returned by time.time(). If optional argument tz is None or
        not specified, the timestamp is converted to the platform's local date
        and time, and the returned datetime object is naive.

        Else tz must be an instance of a class tzinfo subclass, and the
        timestamp is converted to tz's time zone. In this case the result is
        equivalent to
        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).

        fromtimestamp() may raise ValueError, if the timestamp is out of the
        range of values supported by the platform C localtime() or gmtime()
        functions. It's common for this to be restricted to years in 1970
        through 2038. Note that on non-POSIX systems that include leap seconds
        in their notion of a timestamp, leap seconds are ignored by
        fromtimestamp(), and then it's possible to have two timestamps
        differing by a second that yield identical datetime objects.

        See also utcfromtimestamp().
        """
项目:cloud-memory    作者:onejgordon    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def fromtimestamp(timestamp, tz=None):
        """Return the local date and time corresponding to the POSIX timestamp.

        Same as is returned by time.time(). If optional argument tz is None or
        not specified, the timestamp is converted to the platform's local date
        and time, and the returned datetime object is naive.

        Else tz must be an instance of a class tzinfo subclass, and the
        timestamp is converted to tz's time zone. In this case the result is
        equivalent to
        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).

        fromtimestamp() may raise ValueError, if the timestamp is out of the
        range of values supported by the platform C localtime() or gmtime()
        functions. It's common for this to be restricted to years in 1970
        through 2038. Note that on non-POSIX systems that include leap seconds
        in their notion of a timestamp, leap seconds are ignored by
        fromtimestamp(), and then it's possible to have two timestamps
        differing by a second that yield identical datetime objects.

        See also utcfromtimestamp().
        """
项目:FMoviesPlus.bundle    作者:coder-alpha    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:pyfiddleio    作者:priyankcommits    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:LSTM-GA-StockTrader    作者:MartinLidy    | 项目源码 | 文件源码
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def now(tz=None):
        """Return the current local date and time.

        If optional argument tz is None or not specified, this is like today(),
        but, if possible, supplies more precision than can be gotten from going
        through a time.time() timestamp (for example, this may be possible on
        platforms supplying the C gettimeofday() function).

        Else tz must be an instance of a class tzinfo subclass, and the current
        date and time are converted to tz's time zone. In this case the result
        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).

        See also today(), utcnow().
        """
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def fromtimestamp(timestamp, tz=None):
        """Return the local date and time corresponding to the POSIX timestamp.

        Same as is returned by time.time(). If optional argument tz is None or
        not specified, the timestamp is converted to the platform's local date
        and time, and the returned datetime object is naive.

        Else tz must be an instance of a class tzinfo subclass, and the
        timestamp is converted to tz's time zone. In this case the result is
        equivalent to
        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).

        fromtimestamp() may raise ValueError, if the timestamp is out of the
        range of values supported by the platform C localtime() or gmtime()
        functions. It's common for this to be restricted to years in 1970
        through 2038. Note that on non-POSIX systems that include leap seconds
        in their notion of a timestamp, leap seconds are ignored by
        fromtimestamp(), and then it's possible to have two timestamps
        differing by a second that yield identical datetime objects.

        See also utcfromtimestamp().
        """
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def astimezone(tz):
        """Return a datetime object with new tzinfo member tz, adjusting the
        date and time members so the result is the same UTC time as self, but
        in tz's local time.

        tz must be an instance of a tzinfo subclass, and its utcoffset() and
        dst() methods must not return None. self must be aware (self.tzinfo
        must not be None, and self.utcoffset() must not return None).

        If self.tzinfo is tz, self.astimezone(tz) is equal to self: no
        adjustment of date or time members is performed. Else the result is
        local time in time zone tz, representing the same UTC time as self:
            after astz = dt.astimezone(tz), astz - astz.utcoffset()
        will usually have the same date and time members as dt - dt.utcoffset().
        The discussion of class tzinfo explains the cases at Daylight Saving
        Time transition boundaries where this cannot be achieved (an issue only
        if tz models both standard and daylight time).

        If you merely want to attach a time zone object tz to a datetime dt
        without adjustment of date and time members, use dt.replace(tzinfo=tz).
        If you merely want to remove the time zone object from an aware
        datetime dt without conversion of date and time members, use 
        dt.replace(tzinfo=None).

        Note that the default tzinfo.fromutc() method can be overridden in a
        tzinfo subclass to effect the result returned by astimezone().
        """
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def fromutc(dt):
        """Return an equivalent datetime in self's local time."""
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def now(tz=None):
        """Return the current local date and time.

        If optional argument tz is None or not specified, this is like today(),
        but, if possible, supplies more precision than can be gotten from going
        through a time.time() timestamp (for example, this may be possible on
        platforms supplying the C gettimeofday() function).

        Else tz must be an instance of a class tzinfo subclass, and the current
        date and time are converted to tz's time zone. In this case the result
        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).

        See also today(), utcnow().
        """
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def astimezone(tz):
        """Return a datetime object with new tzinfo member tz, adjusting the
        date and time members so the result is the same UTC time as self, but
        in tz's local time.

        tz must be an instance of a tzinfo subclass, and its utcoffset() and
        dst() methods must not return None. self must be aware (self.tzinfo
        must not be None, and self.utcoffset() must not return None).

        If self.tzinfo is tz, self.astimezone(tz) is equal to self: no
        adjustment of date or time members is performed. Else the result is
        local time in time zone tz, representing the same UTC time as self:
            after astz = dt.astimezone(tz), astz - astz.utcoffset()
        will usually have the same date and time members as dt - dt.utcoffset().
        The discussion of class tzinfo explains the cases at Daylight Saving
        Time transition boundaries where this cannot be achieved (an issue only
        if tz models both standard and daylight time).

        If you merely want to attach a time zone object tz to a datetime dt
        without adjustment of date and time members, use dt.replace(tzinfo=tz).
        If you merely want to remove the time zone object from an aware
        datetime dt without conversion of date and time members, use 
        dt.replace(tzinfo=None).

        Note that the default tzinfo.fromutc() method can be overridden in a
        tzinfo subclass to effect the result returned by astimezone().
        """
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def fromutc(dt):
        """Return an equivalent datetime in self's local time."""
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def now(tz=None):
        """Return the current local date and time.

        If optional argument tz is None or not specified, this is like today(),
        but, if possible, supplies more precision than can be gotten from going
        through a time.time() timestamp (for example, this may be possible on
        platforms supplying the C gettimeofday() function).

        Else tz must be an instance of a class tzinfo subclass, and the current
        date and time are converted to tz's time zone. In this case the result
        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).

        See also today(), utcnow().
        """
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def astimezone(tz):
        """Return a datetime object with new tzinfo member tz, adjusting the
        date and time members so the result is the same UTC time as self, but
        in tz's local time.

        tz must be an instance of a tzinfo subclass, and its utcoffset() and
        dst() methods must not return None. self must be aware (self.tzinfo
        must not be None, and self.utcoffset() must not return None).

        If self.tzinfo is tz, self.astimezone(tz) is equal to self: no
        adjustment of date or time members is performed. Else the result is
        local time in time zone tz, representing the same UTC time as self:
            after astz = dt.astimezone(tz), astz - astz.utcoffset()
        will usually have the same date and time members as dt - dt.utcoffset().
        The discussion of class tzinfo explains the cases at Daylight Saving
        Time transition boundaries where this cannot be achieved (an issue only
        if tz models both standard and daylight time).

        If you merely want to attach a time zone object tz to a datetime dt
        without adjustment of date and time members, use dt.replace(tzinfo=tz).
        If you merely want to remove the time zone object from an aware
        datetime dt without conversion of date and time members, use 
        dt.replace(tzinfo=None).

        Note that the default tzinfo.fromutc() method can be overridden in a
        tzinfo subclass to effect the result returned by astimezone().
        """
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def fromutc(dt):
        """Return an equivalent datetime in self's local time."""
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def now(tz=None):
        """Return the current local date and time.

        If optional argument tz is None or not specified, this is like today(),
        but, if possible, supplies more precision than can be gotten from going
        through a time.time() timestamp (for example, this may be possible on
        platforms supplying the C gettimeofday() function).

        Else tz must be an instance of a class tzinfo subclass, and the current
        date and time are converted to tz's time zone. In this case the result
        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).

        See also today(), utcnow().
        """
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def astimezone(tz):
        """Return a datetime object with new tzinfo member tz, adjusting the
        date and time members so the result is the same UTC time as self, but
        in tz's local time.

        tz must be an instance of a tzinfo subclass, and its utcoffset() and
        dst() methods must not return None. self must be aware (self.tzinfo
        must not be None, and self.utcoffset() must not return None).

        If self.tzinfo is tz, self.astimezone(tz) is equal to self: no
        adjustment of date or time members is performed. Else the result is
        local time in time zone tz, representing the same UTC time as self:
            after astz = dt.astimezone(tz), astz - astz.utcoffset()
        will usually have the same date and time members as dt - dt.utcoffset().
        The discussion of class tzinfo explains the cases at Daylight Saving
        Time transition boundaries where this cannot be achieved (an issue only
        if tz models both standard and daylight time).

        If you merely want to attach a time zone object tz to a datetime dt
        without adjustment of date and time members, use dt.replace(tzinfo=tz).
        If you merely want to remove the time zone object from an aware
        datetime dt without conversion of date and time members, use 
        dt.replace(tzinfo=None).

        Note that the default tzinfo.fromutc() method can be overridden in a
        tzinfo subclass to effect the result returned by astimezone().
        """
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def fromutc(dt):
        """Return an equivalent datetime in self's local time."""