本文整理汇总了Python中DateTime.add_century方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.add_century方法的具体用法?Python DateTime.add_century怎么用?Python DateTime.add_century使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime.add_century方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParseDate
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import add_century [as 别名]
def ParseDate(arpastring,parse_arpadate=arpadateRE.match):
""" ParseDate(arpastring)
Returns a DateTime instance reflecting the given ARPA
date. Only the date part is parsed, any time part will be
ignored. The instance's time is set to 0:00:00.
"""
s = arpastring.strip()
date = parse_arpadate(s)
if not date:
raise ValueError,'wrong format'
litday,day,litmonth,month,year = date.groups()
if len(year) == 2:
year = DateTime.add_century(int(year))
else:
year = int(year)
if litmonth:
litmonth = litmonth.lower()
try:
month = litmonthtable[litmonth]
except KeyError:
raise ValueError,'wrong month format'
else:
month = int(month)
day = int(day)
# litday and timezone are ignored
return DateTime.DateTime(year,month,day)
示例2: ParseDateTime
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import add_century [as 别名]
def ParseDateTime(arpastring,parse_arpadatetime=arpadatetimeRE.match):
""" ParseDateTime(arpastring)
Returns a DateTime instance reflecting the given ARPA date
assuming it is local time (timezones are silently ignored).
"""
s = arpastring.strip()
date = parse_arpadatetime(s)
if not date:
raise ValueError,'wrong format or unknown time zone'
litday,day,litmonth,month,year,hour,minute,second,zone = date.groups()
if len(year) == 2:
year = DateTime.add_century(int(year))
else:
year = int(year)
if litmonth:
litmonth = litmonth.lower()
try:
month = litmonthtable[litmonth]
except KeyError:
raise ValueError,'wrong month format'
else:
month = int(month)
day = int(day)
hour = int(hour)
minute = int(minute)
if second is None:
second = 0.0
else:
second = float(second)
# litday and timezone are ignored
return DateTime.DateTime(year,month,day,hour,minute,second)
示例3: ParseDateTimeGMT
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import add_century [as 别名]
def ParseDateTimeGMT(arpastring,parse_arpadatetime=arpadatetimeRE.match,
strip=string.strip,atoi=string.atoi,atof=string.atof,
lower=string.lower):
"""ParseDateTimeGMT(arpastring)
Returns a DateTime instance reflecting the given ARPA date converting
it to UTC (timezones are honored).
"""
s = strip(arpastring)
date = parse_arpadatetime(s)
if not date:
raise ValueError,'wrong format or unknown time zone'
litday,day,litmonth,month,year,hour,minute,second,zone = date.groups()
if len(year) == 2:
year = DateTime.add_century(atoi(year))
else:
year = atoi(year)
if litmonth:
litmonth = lower(litmonth)
try:
month = litmonthtable[litmonth]
except KeyError:
raise ValueError,'wrong month format'
else:
month = atoi(month)
day = atoi(day)
hour = atoi(hour)
minute = atoi(minute)
if second is None:
second = 0.0
else:
second = atof(second)
offset = Timezone.utc_offset(zone)
# litday is ignored
return DateTime.DateTime(year,month,day,hour,minute,second) - offset