Windows file creation date/time using python

前端 未结 4 867
长发绾君心
长发绾君心 2020-12-21 13:29

I need to get a file creation date&time using python. I tried:

os.stat(r\"path\")[ST_CTIME]

But it is returning:

126353         


        
4条回答
  •  没有蜡笔的小新
    2020-12-21 14:26

    From bytes.com:

    import os
    import time
    create_date = os.stat('/tmp/myfile.txt')[9]
    print time.strftime("%Y-%m-%d", time.gmtime(create_date))
    

    Which gives:

    2009-11-25
    

    You can also try:

    print time.gmtime(create_date)
    (2009, 11, 25, 13, 37, 9, 2, 329, 0)
    

    For a more accurate timestamp.

    Note that the time returned by time.gmtime() returns GMT; See the time module documentation for other functions, like localtime().

提交回复
热议问题