Python datetime.time 模块,localtime() 实例源码

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

项目: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().
        """
项目: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().
        """
项目: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().
        """
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def fromtimestamp(timestamp):
        """Return the local date from a POSIX timestamp (like time.time())

        This may raise ValueError, if the timestamp is out of the range of
        values supported by the platform C localtime() function. It's common
        for this to be restricted to years from 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().
        """
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime().

        The hours, minutes and seconds are 0, and the DST flag is -1.
        d.timetuple() is equivalent to
        (d.year, d.month, d.day, 0, 0, 0, d.weekday(), d.toordinal() -
        date(d.year, 1, 1).toordinal() + 1, -1)
        """
项目: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 timetuple():
        """Return a 9-element tuple of the form returned by time.localtime()."""
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def fromtimestamp(timestamp):
        """Return the local date from a POSIX timestamp (like time.time())

        This may raise ValueError, if the timestamp is out of the range of
        values supported by the platform C localtime() function. It's common
        for this to be restricted to years from 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().
        """
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime().

        The hours, minutes and seconds are 0, and the DST flag is -1.
        d.timetuple() is equivalent to
        (d.year, d.month, d.day, 0, 0, 0, d.weekday(), d.toordinal() -
        date(d.year, 1, 1).toordinal() + 1, -1)
        """
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime()."""
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_microsecond_rounding(self):
        for fts in [self.theclass.fromtimestamp,
                    self.theclass.utcfromtimestamp]:
            zero = fts(0)
            self.assertEqual(zero.second, 0)
            self.assertEqual(zero.microsecond, 0)
            try:
                minus_one = fts(-1e-6)
            except OSError:
                # localtime(-1) and gmtime(-1) is not supported on Windows
                pass
            else:
                self.assertEqual(minus_one.second, 59)
                self.assertEqual(minus_one.microsecond, 999999)

                t = fts(-1e-8)
                self.assertEqual(t, minus_one)
                t = fts(-9e-7)
                self.assertEqual(t, minus_one)
                t = fts(-1e-7)
                self.assertEqual(t, minus_one)

            t = fts(1e-7)
            self.assertEqual(t, zero)
            t = fts(9e-7)
            self.assertEqual(t, zero)
            t = fts(0.99999949)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 999999)
            t = fts(0.9999999)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 999999)
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def fromtimestamp(timestamp):
        """Return the local date from a POSIX timestamp (like time.time())

        This may raise ValueError, if the timestamp is out of the range of
        values supported by the platform C localtime() function. It's common
        for this to be restricted to years from 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().
        """
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime().

        The hours, minutes and seconds are 0, and the DST flag is -1.
        d.timetuple() is equivalent to
        (d.year, d.month, d.day, 0, 0, 0, d.weekday(), d.toordinal() -
        date(d.year, 1, 1).toordinal() + 1, -1)
        """
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime()."""
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_microsecond_rounding(self):
        for fts in [self.theclass.fromtimestamp,
                    self.theclass.utcfromtimestamp]:
            zero = fts(0)
            self.assertEqual(zero.second, 0)
            self.assertEqual(zero.microsecond, 0)
            one = fts(1e-6)
            try:
                minus_one = fts(-1e-6)
            except OSError:
                # localtime(-1) and gmtime(-1) is not supported on Windows
                pass
            else:
                self.assertEqual(minus_one.second, 59)
                self.assertEqual(minus_one.microsecond, 999999)

                t = fts(-1e-8)
                self.assertEqual(t, zero)
                t = fts(-9e-7)
                self.assertEqual(t, minus_one)
                t = fts(-1e-7)
                self.assertEqual(t, zero)
                t = fts(-1/2**7)
                self.assertEqual(t.second, 59)
                self.assertEqual(t.microsecond, 992188)

            t = fts(1e-7)
            self.assertEqual(t, zero)
            t = fts(9e-7)
            self.assertEqual(t, one)
            t = fts(0.99999949)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 999999)
            t = fts(0.9999999)
            self.assertEqual(t.second, 1)
            self.assertEqual(t.microsecond, 0)
            t = fts(1/2**7)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 7812)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def fromtimestamp(timestamp):
        """Return the local date from a POSIX timestamp (like time.time())

        This may raise ValueError, if the timestamp is out of the range of
        values supported by the platform C localtime() function. It's common
        for this to be restricted to years from 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().
        """
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime().

        The hours, minutes and seconds are 0, and the DST flag is -1.
        d.timetuple() is equivalent to
        (d.year, d.month, d.day, 0, 0, 0, d.weekday(), d.toordinal() -
        date(d.year, 1, 1).toordinal() + 1, -1)
        """
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def timetuple():
        """Return a 9-element tuple of the form returned by time.localtime()."""
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_fromtimestamp(self):
        import time

        ts = time.time()
        expected = time.localtime(ts)
        got = self.theclass.fromtimestamp(ts)
        self.verify_field_equality(expected, got)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_microsecond_rounding(self):
        for fts in [self.theclass.fromtimestamp,
                    self.theclass.utcfromtimestamp]:
            zero = fts(0)
            self.assertEqual(zero.second, 0)
            self.assertEqual(zero.microsecond, 0)
            try:
                minus_one = fts(-1e-6)
            except OSError:
                # localtime(-1) and gmtime(-1) is not supported on Windows
                pass
            else:
                self.assertEqual(minus_one.second, 59)
                self.assertEqual(minus_one.microsecond, 999999)

                t = fts(-1e-8)
                self.assertEqual(t, minus_one)
                t = fts(-9e-7)
                self.assertEqual(t, minus_one)
                t = fts(-1e-7)
                self.assertEqual(t, minus_one)

            t = fts(1e-7)
            self.assertEqual(t, zero)
            t = fts(9e-7)
            self.assertEqual(t, zero)
            t = fts(0.99999949)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 999999)
            t = fts(0.9999999)
            self.assertEqual(t.second, 0)
            self.assertEqual(t.microsecond, 999999)