Scrapy将时间缩短2小时。 价值2013-05-30 14:50:54 +0200与'start_time'不同:datetime.datetime(2013,5,30, 12,50,53 , 860000)
2013-05-30 14:50:54+0200 [myspider] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 120,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 382,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2013, 5, 30, 12, 50, 53, 887000),
'httpcache/hits': 1,
'log_count/DEBUG': 7,
'log_count/INFO': 4,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2013, 5, 30, 12, 50, 53, 860000)}
2013-05-30 14:50:54+0200 [myspider] INFO: Spider closed (finished)
在我的蜘蛛中,我有一个使用datetime.datetime.now()的变量,并且正确分配了此变量的时间戳。
是否可以在scrapy中设置时区?
答案 0 :(得分:0)
Scrapy将时间缩短2小时。
正如你所说,scrapy只有以不同的格式显示时间,但日期 - 时间值是相同的。
如你所说,它不是不同。
2013-05-30 14:50:54+0200
与2013-05-30 12:50:54+0000
更新:
所以你想用当地时区打印日期时间。查看scrapy源是看它使用twisted logging,它具有以下功能:
def formatTime(self, when):
"""
Format the given UTC value as a string representing that time in the
local timezone.
By default it's formatted as a ISO8601-like string (ISO8601 date and
ISO8601 time separated by a space). It can be customized using the
C{timeFormat} attribute, which will be used as input for the underlying
L{datetime.datetime.strftime} call.
@type when: C{int}
@param when: POSIX (ie, UTC) timestamp for which to find the offset.
@rtype: C{str}
"""
if self.timeFormat is not None:
return datetime.fromtimestamp(when).strftime(self.timeFormat)
tzOffset = -self.getTimezoneOffset(when)
when = datetime.utcfromtimestamp(when + tzOffset)
tzHour = abs(int(tzOffset / 60 / 60))
tzMin = abs(int(tzOffset / 60 % 60))
if tzOffset < 0:
tzSign = '-'
else:
tzSign = '+'
return '%d-%02d-%02d %02d:%02d:%02d%s%02d%02d' % (
when.year, when.month, when.day,
when.hour, when.minute, when.second,
tzSign, tzHour, tzMin)