15
我想從Python獲取UTC格式文件的修改日期。以下代碼返回Linux配置時區(GMT-5)中的日期。我需要它在UTC。或者我如何獲得os配置的時區來使用pytz轉換它?如何從Python獲取UTC格式的文件修改日期
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> import os
>>> dt=os.path.getmtime('/home/user/.bashrc')
>>> datetime.datetime.fromtimestamp(dt)
datetime(2012, 5, 30, 21, 18, 10)
感謝