我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用datetime.time.gmtime()。
def test_utcfromtimestamp(self): import time ts = time.time() expected = time.gmtime(ts) got = self.theclass.utcfromtimestamp(ts) self.verify_field_equality(expected, got)
def test_utcfromtimestamp(self): import time ts = time.time() expected = time.gmtime(ts) got = self.theclass.utcfromtimestamp(ts) self.verify_field_equality(expected, got) # Run with US-style DST rules: DST begins 2 a.m. on second Sunday in # March (M3.2.0) and ends 2 a.m. on first Sunday in November (M11.1.0).
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)
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)