I am trying to set the mod time and access time of a file in python (3.5) using os.utime but am seeing some weird behavior.
我正在尝试使用os在python(3.5)中设置文件的mod时间和访问时间。但是我看到一些奇怪的行为。
unixtime = time.mktime(object.last_modified.timetuple()) # unixtime = 1497658235.0
os.utime(local_file, (unixtime, unixtime))
Then when I check the mod time in terminal my mod time has the correct day but the time seems to just be the year.
然后当我在终端上检查mod时间时,我的mod时间是正确的,但时间似乎是一年。
[bob@macbook:~/]$ ll
drwxr-xr-x 4 331-BOB staff 136B Jun 16 11:11 temp
-rw-r--r-- 1 331-BOB staff 0B Jun 16 2017 tester.txt
1 个解决方案
#1
0
So seems there was a discrepancy between the timezone of the datetime object I was using (UTC) and the local time on my computer (Mountain). This caused the mod date I was trying to attach to the file to be in the future and I guess the OS just displayed the year and not the exact time because of that.
因此,我所使用的datetime对象的时区(UTC)与我的计算机(Mountain)上的本地时间(local time)之间似乎存在差异。这导致了我试图附加到文件上的mod日期为in the future,我猜操作系统只是显示了年份而不是确切的时间。
#1
0
So seems there was a discrepancy between the timezone of the datetime object I was using (UTC) and the local time on my computer (Mountain). This caused the mod date I was trying to attach to the file to be in the future and I guess the OS just displayed the year and not the exact time because of that.
因此,我所使用的datetime对象的时区(UTC)与我的计算机(Mountain)上的本地时间(local time)之间似乎存在差异。这导致了我试图附加到文件上的mod日期为in the future,我猜操作系统只是显示了年份而不是确切的时间。