本文整理汇总了Python中DateTime.DateTime.second方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.second方法的具体用法?Python DateTime.second怎么用?Python DateTime.second使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.second方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dt_setter
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def _dt_setter(self, fieldtoset, value, **kwargs):
# Always set the date in UTC, saving the timezone in another field.
# But since the timezone value isn't known at the time of saving the
# form, we have to save it timezone-naive first and let
# timezone_handler convert it to the target zone afterwards.
# Note: The name of the first parameter shouldn't be field, because
# it's already in kwargs in some case.
if not isinstance(value, DateTime): value = DateTime(value)
# Get microseconds from seconds, which is a floating value. Round it
# up, to bypass precision errors.
micro = int(round(value.second()%1 * 1000000))
value = DateTime('%04d-%02d-%02dT%02d:%02d:%02d%sZ' % (
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
micro and '.%s' % micro or ''
)
)
self.getField(fieldtoset).set(self, value, **kwargs)
示例2: testRFC822
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testRFC822(self):
# rfc822 conversion
dt = DateTime('2002-05-02T08:00:00+00:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0000')
dt = DateTime('2002-05-02T08:00:00+02:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0200')
dt = DateTime('2002-05-02T08:00:00-02:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 -0200')
# Checking that conversion from local time is working.
dt = DateTime()
dts = dt.rfc822().split(' ')
times = dts[4].split(':')
_isDST = time.localtime(time.time())[8]
if _isDST:
offset = time.altzone
else:
offset = time.timezone
self.assertEqual(dts[0], dt.aDay() + ',')
self.assertEqual(int(dts[1]), dt.day())
self.assertEqual(dts[2], dt.aMonth())
self.assertEqual(int(dts[3]), dt.year())
self.assertEqual(int(times[0]), dt.h_24())
self.assertEqual(int(times[1]), dt.minute())
self.assertEqual(int(times[2]), int(dt.second()))
self.assertEqual(dts[5], "%+03d%02d" % divmod((-offset / 60), 60))
示例3: testTZ2
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testTZ2(self):
# Time zone manipulation test 2
dt = DateTime()
dt1 = dt.toZone('GMT')
s = dt.second()
s1 = dt1.second()
self.assertEqual(s, s1, (dt, dt1, s, s1))
示例4: testConstructor7
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testConstructor7(self):
"""Constructor from parts"""
dt = DateTime()
dt1 = DateTime(dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(), dt.timezone())
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt), repr(dt1))
示例5: testSubtraction
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testSubtraction(self):
"""Reconstruction of a DateTime from its parts, with subtraction"""
dt = DateTime()
dt1 = dt - 3.141592653
dt2 = DateTime(dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second())
dt3 = dt2 - 3.141592653
self.assertEqual(dt1, dt3, (dt, dt1, dt2, dt3))
示例6: testSubtraction
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testSubtraction(self):
# Reconstruction of a DateTime from its parts, with subtraction
# this also tests the accuracy of addition and reconstruction
dt = DateTime()
dt1 = dt - 3.141592653
dt2 = DateTime(
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second())
dt3 = dt2 - 3.141592653
self.assertEqual(dt1, dt3, (dt, dt1, dt2, dt3))
示例7: testConstructor3
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def testConstructor3(self):
# Constructor from date/time string
dt = DateTime()
dt1s = '%d/%d/%d %d:%d:%f %s' % (
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.timezone())
dt1 = DateTime(dt1s)
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt), repr(dt1))
示例8: fromLineFrom
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def fromLineFrom(self,email,date):
"""
Generate a conformant mbox From line from email and date strings.
(unless date is unparseable, in which case we omit that part)
"""
# "email" is in fact a real name or zwiki username - adapt it
email = re.sub(r'\s','',email) or 'unknown'
try:
d = DateTime(date)
return 'From %s %s %s %d %02d:%02d:%02d %s %d\n' % (
email,d.aDay(),d.aMonth(),d.day(),d.hour(),
d.minute(),d.second(),d.timezone(),d.year())
except (DateTimeSyntaxError,AttributeError,IndexError):
return 'From %s\n' % email
示例9: _dt_setter
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import second [as 别名]
def _dt_setter(self, fieldtoset, value, **kwargs):
# Always set the date in UTC, saving the timezone in another field.
# But since the timezone value isn't known at the time of saving the
# form, we have to save it timezone-naive first and let
# timezone_handler convert it to the target zone afterwards.
# Note: The name of the first parameter shouldn't be field, because
# it's already in kwargs in some case.
if not isinstance(value, DateTime): value = DateTime(value)
value = DateTime('%04d-%02d-%02dT%02d:%02d:%02dZ' % (
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second())
)
self.getField(fieldtoset).set(self, value, **kwargs)