我有一个django应用程序,我用uWSGI和nginx设置Django和我的web服务器。我有一个为我的文件设置访问时间的函数,这是我的函数:
from shutil import move
from time import mktime
from os import utime
def spool(self, time=None):
if time:
try:
time = mktime(time.timetuple())
utime(path(self.tempdir) / path(self.filename), (time, time))
except (error, AttributeError, OverflowError, ValueError):
raise InvalidTimeError
try:
move(path(self.tempdir) / path(self.filename),
path(self.spool_dir) / path(self.filename))
except IOError:
raise NoSpoolPermissionError
当我使用python命令运行此函数时,访问时间是正确的:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561550 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 11:27:30.000000000 +0430
Modify: 2013-08-21 11:27:30.000000000 +0430
Change: 2013-08-21 11:24:00.142143170 +0430
Birth: -
但是当我在我的django应用程序中运行该函数时,输出为:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 242 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561542 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 21:15:00.000000000 +0430
Modify: 2013-08-21 21:15:00.000000000 +0430
Change: 2013-08-21 11:44:42.982093206 +0430
Birth: -
正如您所见,访问时间是<< 2013-08-21 21:15:00>>但必须是<<< 2013-08-21 11:44:42>>而且我不知道发生了什么。 linux date命令输出为:
root@demo:~# date
Wed Aug 21 11:44:55 IRDT 2013
和python datetime输出:
>>> datetime.datetime.now()
datetime.datetime(2013, 8, 21, 11, 45, 57, 886360)
答案 0 :(得分:1)
检查webserver conf和django设置中的时区设置是否设置为适当的值。
wsgi / django环境中的时间将受这些配置文件中的时区设置的影响。